Skip to content

Commit

Permalink
Removed setters, passing options on constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Cordeiro committed Oct 23, 2019
1 parent e416091 commit ca64dc3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
38 changes: 8 additions & 30 deletions src/Provider/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,48 +65,26 @@ class Mollie extends AbstractProvider

public function __construct(array $options = [], array $collaborators = [])
{
parent::__construct($options, $collaborators);

if (isset($options["clientId"]) && strpos($options["clientId"], self::CLIENT_ID_PREFIX) !== 0) {
throw new \DomainException("Mollie needs the client ID to be prefixed with " . self::CLIENT_ID_PREFIX . ".");
}

$this->mollieApiUrl = (isset($options['mollieApiUrl']) ? $options['mollieApiUrl'] : null) ?: self::MOLLIE_API_URL;
$this->mollieWebUrl = (isset($options['mollieWebUrl']) ? $options['mollieWebUrl'] : null) ?: self::MOLLIE_WEB_URL;
unset($options['mollieApiUrl'], $options['mollieWebUrl']);

parent::__construct($options, $collaborators);
}

/**
* @var string
*/
private $mollieApiUrl = self::MOLLIE_API_URL;
private $mollieApiUrl;

/**
* @var string
*/
private $mollieWebUrl = self::MOLLIE_WEB_URL;

/**
* Define Mollie api URL
*
* @param string $url
* @return Mollie
*/
public function setMollieApiUrl ($url)
{
$this->mollieApiUrl = $url;

return $this;
}

/**
* Define Mollie web URL
*
* @param string $url
* @return Mollie
*/
public function setMollieWebUrl ($url)
{
$this->mollieWebUrl = $url;

return $this;
}
private $mollieWebUrl;

/**
* Returns the base URL for authorizing a client.
Expand Down
22 changes: 12 additions & 10 deletions tests/src/Provider/MollieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ class MollieTest extends \PHPUnit_Framework_TestCase
const MOCK_SECRET = 'mock_secret';
const REDIRECT_URI = 'none';

const OPTIONS = [
'clientId' => self::MOCK_CLIENT_ID,
'clientSecret' => self::MOCK_SECRET,
'redirectUri' => self::REDIRECT_URI,
];

protected $provider;

protected function setUp()
{
$this->provider = new Mollie([
'clientId' => self::MOCK_CLIENT_ID,
'clientSecret' => self::MOCK_SECRET,
'redirectUri' => self::REDIRECT_URI,
]);
$this->provider = new Mollie(self::OPTIONS);
}

public function tearDown()
Expand All @@ -35,7 +37,7 @@ public function testClientIdShouldThrowExceptionWhenNotPrefixed()
$this->expectException(\DomainException::class);
$this->expectExceptionMessage("Mollie needs the client ID to be prefixed with " . Mollie::CLIENT_ID_PREFIX . ".");

$provider = new \Mollie\OAuth2\Client\Provider\Mollie([
new Mollie([
'clientId' => 'not_pefixed_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
Expand Down Expand Up @@ -215,18 +217,18 @@ public function testUserData()

public function testWhenDefiningADifferentMollieApiUrlThenUseThisOnApiCalls()
{
$provider = new Mollie(['clientId' => self::MOCK_CLIENT_ID, 'clientSecret' => '', 'redirectUri' => '']);
$options = array_merge(['mollieApiUrl' => 'https://api.mollie.nl'], self::OPTIONS);

$provider->setMollieApiUrl('https://api.mollie.nl');
$provider = new Mollie($options);

$this->assertEquals('https://api.mollie.nl/oauth2/tokens', $provider->getBaseAccessTokenUrl([]));
}

public function testWhenDefiningADifferentMollieWebUrlThenUseThisForAuthorize()
{
$provider = new Mollie(['clientId' => self::MOCK_CLIENT_ID, 'clientSecret' => '', 'redirectUri' => '']);
$options = array_merge(['mollieWebUrl' => 'https://www.mollie.nl'], self::OPTIONS);

$provider->setMollieWebUrl('https://www.mollie.nl');
$provider = new Mollie($options);

list($url) = explode('?', $provider->getAuthorizationUrl());
$this->assertEquals('https://www.mollie.nl/oauth2/authorize', $url);
Expand Down

0 comments on commit ca64dc3

Please sign in to comment.