From 7ba2a97a29ba73fc3f1531a66d9d1539f0c1dc16 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Sat, 28 Aug 2021 12:04:35 +0200 Subject: [PATCH] Add additional getters (#23) --- src/Provider/MollieResourceOwner.php | 26 +++++++++++++++++++- tests/src/Provider/MollieTest.php | 36 ++++++++++++++++++---------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/Provider/MollieResourceOwner.php b/src/Provider/MollieResourceOwner.php index 45ab380..1d67f7c 100644 --- a/src/Provider/MollieResourceOwner.php +++ b/src/Provider/MollieResourceOwner.php @@ -40,4 +40,28 @@ public function toArray () { return $this->response; } -} \ No newline at end of file + + /** + * @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; + } +} diff --git a/tests/src/Provider/MollieTest.php b/tests/src/Provider/MollieTest.php index 5a596c4..6b791c3 100644 --- a/tests/src/Provider/MollieTest.php +++ b/tests/src/Provider/MollieTest.php @@ -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 @@ -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": "info@mollie.com", "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" @@ -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('info@mollie.com', $array['email']); + $this->assertEquals('info@mollie.com', $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()