Skip to content

Commit

Permalink
Add additional getters (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtkamp authored Aug 28, 2021
1 parent fde192d commit 7ba2a97
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
26 changes: 25 additions & 1 deletion src/Provider/MollieResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,28 @@ public function toArray ()
{
return $this->response;
}
}

/**
* @return string|null
*/
public function getEmail()
{
return isset($this->response['email']) ? $this->response['email'] : null;
}

/**
* @return string|null
*/
public function getRegistrationNumber()
{
return isset($this->response['registrationNumber']) ? $this->response['registrationNumber'] : null;
}

/**
* @return string|null
*/
public function getVatNumber()
{
return isset($this->response['vatNumber']) ? $this->response['vatNumber'] : null;
}
}
36 changes: 24 additions & 12 deletions tests/src/Provider/MollieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use League\OAuth2\Client\Token\AccessToken;
use Mockery as m;
use Mollie\OAuth2\Client\Provider\Mollie;
use Mollie\OAuth2\Client\Provider\MollieResourceOwner;
use Psr\Http\Message\ResponseInterface;

class MollieTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -186,21 +187,26 @@ public function testUserData()
$accountResponse->shouldReceive('getBody')->andReturn(
'{
"resource": "organization",
"id": "org_162634",
"name": "Kicks To The Face B.V.",
"id": "org_12345678",
"name": "Mollie B.V.",
"email": "[email protected]",
"address": {
"streetAndNumber": "Keizersgracht 313",
"postalCode": "1016 EE",
"streetAndNumber": "Keizersgracht 126",
"postalCode": "1015 CW",
"city": "Amsterdam",
"country": "NL"
},
"registrationNumber": "370355724",
"registrationNumber": "30204462",
"vatNumber": "NL815839091B01"
"_links": {
"self": {
"href": "https://api.mollie.com/v2/organizations/me",
"href": "https://api.mollie.com/v2/organizations/org_12345678",
"type": "application/hal+json"
},
"dashboard": {
"href": "https://mollie.com/dashboard/org_12345678",
"type": "text/html"
},
"chargebacks": {
"href": "https://api.mollie.com/v2/chargebacks",
"type": "application/hal+json"
Expand Down Expand Up @@ -248,22 +254,28 @@ public function testUserData()
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$account = $this->provider->getResourceOwner($token);

assert($account instanceof MollieResourceOwner);

$array = $account->toArray();

$this->assertEquals('org_162634', $account->getId());
$this->assertEquals('org_162634', $array['id']);
$this->assertEquals('Kicks To The Face B.V.', $array['name']);
$this->assertEquals('org_12345678', $account->getId());
$this->assertEquals('org_12345678', $array['id']);
$this->assertEquals('Mollie B.V.', $array['name']);
$this->assertEquals('[email protected]', $array['email']);
$this->assertEquals('[email protected]', $account->getEmail());
$this->assertEquals(
[
"streetAndNumber" => "Keizersgracht 313",
"postalCode" => "1016 EE",
"streetAndNumber" => "Keizersgracht 126",
"postalCode" => "1015 CW",
"city" => "Amsterdam",
"country" => "NL",
],
$array['address']
);
$this->assertEquals('370355724', $array['registrationNumber']);
$this->assertEquals('30204462', $array['registrationNumber']);
$this->assertEquals('30204462', $account->getRegistrationNumber());
$this->assertEquals('NL815839091B01', $array['vatNumber']);
$this->assertEquals('NL815839091B01', $account->getVatNumber());
}

public function testWhenDefiningADifferentMollieApiUrlThenUseThisOnApiCalls()
Expand Down

0 comments on commit 7ba2a97

Please sign in to comment.