diff --git a/.travis.yml b/.travis.yml index 1a939c3..a38ff3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,14 @@ jobs: php: "7.2" - <<: *compatibility php: "7.3" + - <<: *test + stage: Analyze + name: Sonarcloud + dist: trusty + addons: + sonarcloud: + organization: "getyoti" + if: type == pull_request OR branch = master + script: + - composer coverage-clover + - sonar-scanner diff --git a/README.md b/README.md index 2f6a5b6..fe51043 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Yoti PHP Sandbox SDK +[![Build Status](https://travis-ci.com/getyoti/yoti-php-sdk-sandbox.svg?branch=master)](https://travis-ci.com/getyoti/yoti-php-sdk-sandbox) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=coverage)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox) +[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=bugs)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox) +[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=code_smells)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox) +[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox) + This repository contains the tools you need to test your Yoti integration. ## Installing the Sandbox diff --git a/composer.json b/composer.json index ce4315f..120b46e 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "yoti/yoti-php-sdk-sandbox", "description": "Yoti PHP SDK Sandbox", - "version": "1.1.0", + "version": "1.2.0", "keywords": [ "yoti", "sdk" @@ -12,7 +12,7 @@ "yoti/yoti-php-sdk": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.5", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.2", "squizlabs/php_codesniffer": "^3.4", "friendsofphp/php-cs-fixer": "^2.15", "brainmaestro/composer-git-hooks": "^2.8", diff --git a/examples/profile/tests/ProfileTest.php b/examples/profile/tests/ProfileTest.php index cd81741..d675010 100644 --- a/examples/profile/tests/ProfileTest.php +++ b/examples/profile/tests/ProfileTest.php @@ -7,6 +7,8 @@ use PHPUnit\Framework\TestCase as PHPUnitTestCase; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAgeVerification; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAnchor; +use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraDataBuilder; +use Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty\SandboxAttributeIssuanceDetailsBuilder; use Yoti\Sandbox\Profile\Request\TokenRequestBuilder; use Yoti\Sandbox\Profile\SandboxClient; use Yoti\YotiClient; @@ -54,6 +56,17 @@ public function shouldReturnUserProfile() new \DateTime('1980-01-01') ); + $expiryDate = new \DateTime('+1 day'); + $extraData = (new SandboxExtraDataBuilder()) + ->withDataEntry( + (new SandboxAttributeIssuanceDetailsBuilder()) + ->withDefinition('some-definition') + ->withExpiryDate($expiryDate) + ->withIssuanceToken('some-token') + ->build() + ) + ->build(); + $tokenRequest = (new TokenRequestBuilder()) ->setRememberMeId('Some Remember Me ID') ->setGivenNames('Some Given Names', $anchors) @@ -71,6 +84,7 @@ public function shouldReturnUserProfile() 'building_number' => 1, 'address_line1' => 'Some Address', ])) + ->setExtraData($extraData) ->build(); $token = $this->sandboxClient->setupSharingProfile($tokenRequest); @@ -104,5 +118,16 @@ public function shouldReturnUserProfile() $this->assertEquals('PASSPORT', $profile->getGivenNames()->getSources()[0]->getValue()); $this->assertEquals('YOTI_ADMIN', $profile->getGivenNames()->getVerifiers()[0]->getValue()); + + $attributeIssuanceDetails = $activityDetails->getExtraData()->getAttributeIssuanceDetails(); + $this->assertEquals(base64_encode('some-token'), $attributeIssuanceDetails->getToken()); + $this->assertEquals( + $expiryDate->format(DATE_RFC3339), + $attributeIssuanceDetails->getExpiryDate()->format(DATE_RFC3339) + ); + $this->assertEquals( + 'some-definition', + $attributeIssuanceDetails->getIssuingAttributes()[0]->getName() + ); } } diff --git a/sonar-project.properties b/sonar-project.properties index a6c70eb..d4d3cf1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,7 @@ sonar.organization = getyoti sonar.projectKey = getyoti:php-sandbox sonar.projectName = PHP SDK Sandbox -sonar.projectVersion = 1.1.0 +sonar.projectVersion = 1.2.0 sonar.language = php sonar.sources=src diff --git a/src/Profile/Request/ExtraData/SandboxDataEntry.php b/src/Profile/Request/ExtraData/SandboxDataEntry.php new file mode 100644 index 0000000..174c11d --- /dev/null +++ b/src/Profile/Request/ExtraData/SandboxDataEntry.php @@ -0,0 +1,39 @@ +type = $type; + $this->value = $value; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'type' => $this->type, + 'value' => $this->value, + ]; + } +} diff --git a/src/Profile/Request/ExtraData/SandboxExtraData.php b/src/Profile/Request/ExtraData/SandboxExtraData.php new file mode 100644 index 0000000..ed4b08c --- /dev/null +++ b/src/Profile/Request/ExtraData/SandboxExtraData.php @@ -0,0 +1,34 @@ +dataEntries = $dataEntries; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'data_entry' => $this->dataEntries, + ]; + } +} diff --git a/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php b/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php new file mode 100644 index 0000000..8b7f55f --- /dev/null +++ b/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php @@ -0,0 +1,32 @@ +dataEntries[] = $dataEntry; + return $this; + } + + /** + * @return SandboxExtraData + */ + public function build(): SandboxExtraData + { + return new SandboxExtraData($this->dataEntries); + } +} diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetails.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetails.php new file mode 100644 index 0000000..da5ac5b --- /dev/null +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetails.php @@ -0,0 +1,20 @@ +issuanceToken = $issuanceToken; + return $this; + } + + /** + * @param \DateTime $expiryDate + * + * @return $this + */ + public function withExpiryDate(\DateTime $expiryDate): self + { + $this->expiryDate = $expiryDate; + return $this; + } + + /** + * @param string $definition + * + * @return self + */ + public function withDefinition(string $definition): self + { + Validation::notEmptyString($definition, 'definition'); + $this->definitions[] = new SandboxDefinition($definition); + return $this; + } + + /** + * @return SandboxAttributeIssuanceDetails + */ + public function build(): SandboxAttributeIssuanceDetails + { + $value = new SandboxAttributeIssuanceDetailsValue( + $this->issuanceToken, + new SandboxIssuingAttributes($this->expiryDate, $this->definitions) + ); + return new SandboxAttributeIssuanceDetails($value); + } +} diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValue.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValue.php new file mode 100644 index 0000000..01d1dcf --- /dev/null +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValue.php @@ -0,0 +1,39 @@ +issuanceToken = $issuanceToken; + $this->issuingAttributes = $issuingAttributes; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'issuance_token' => $this->issuanceToken, + 'issuing_attributes' => $this->issuingAttributes, + ]; + } +} diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxDefinition.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxDefinition.php new file mode 100644 index 0000000..3304680 --- /dev/null +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxDefinition.php @@ -0,0 +1,34 @@ +name = $name; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'name' => $this->name, + ]; + } +} diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php new file mode 100644 index 0000000..89bac90 --- /dev/null +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php @@ -0,0 +1,45 @@ +expiryDate = $expiryDate; + + Validation::isArrayOfType($definitions, [SandboxDefinition::class], 'definitions'); + $this->definitions = $definitions; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'expiry_date' => $this->expiryDate + ->setTimezone(new \DateTimeZone('UTC')) + ->format(\DateTime::RFC3339_EXTENDED), + 'definitions' => $this->definitions, + ]; + } +} diff --git a/src/Profile/Request/TokenRequest.php b/src/Profile/Request/TokenRequest.php index 4d7c6c1..9c054bd 100644 --- a/src/Profile/Request/TokenRequest.php +++ b/src/Profile/Request/TokenRequest.php @@ -6,6 +6,8 @@ use Yoti\Http\Payload; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAttribute; +use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraData; +use Yoti\Util\Json; use Yoti\Util\Validation; class TokenRequest implements \JsonSerializable @@ -20,16 +22,23 @@ class TokenRequest implements \JsonSerializable */ private $sandboxAttributes; + /** + * @var SandboxExtraData|null + */ + private $extraData; + /** * @param string|null $rememberMeId * @param SandboxAttribute[] $sandboxAttributes */ - public function __construct(?string $rememberMeId, array $sandboxAttributes) + public function __construct(?string $rememberMeId, array $sandboxAttributes, ?SandboxExtraData $extraData = null) { $this->rememberMeId = $rememberMeId; Validation::isArrayOfType($sandboxAttributes, [ SandboxAttribute::class ], 'sandboxAttributes'); $this->sandboxAttributes = $sandboxAttributes; + + $this->extraData = $extraData; } /** @@ -37,10 +46,11 @@ public function __construct(?string $rememberMeId, array $sandboxAttributes) */ public function jsonSerialize(): array { - return [ + return Json::withoutNullValues([ 'remember_me_id' => $this->rememberMeId, 'profile_attributes' => $this->sandboxAttributes, - ]; + 'extra_data' => $this->extraData, + ]); } /** diff --git a/src/Profile/Request/TokenRequestBuilder.php b/src/Profile/Request/TokenRequestBuilder.php index ee19aab..3e6aaea 100644 --- a/src/Profile/Request/TokenRequestBuilder.php +++ b/src/Profile/Request/TokenRequestBuilder.php @@ -8,6 +8,7 @@ use Yoti\Sandbox\Profile\Request\Attribute\SandboxAgeVerification; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAttribute; use Yoti\Sandbox\Profile\Request\Attribute\SandboxDocumentDetails; +use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraData; class TokenRequestBuilder { @@ -21,6 +22,11 @@ class TokenRequestBuilder */ private $sandboxAttributes = []; + /** + * @var SandboxExtraData|null + */ + private $extraData; + /** * @param string $value */ @@ -263,6 +269,17 @@ public function addAttribute(SandboxAttribute $attribute): self return $this; } + /** + * @param SandboxExtraData $extraData + * + * @return self + */ + public function setExtraData(SandboxExtraData $extraData): self + { + $this->extraData = $extraData; + return $this; + } + /** * @param string $name * @param string $value @@ -314,6 +331,6 @@ private function getAnchors($anchors, array $args, string $method): array */ public function build(): TokenRequest { - return new TokenRequest($this->rememberMeId, $this->sandboxAttributes); + return new TokenRequest($this->rememberMeId, $this->sandboxAttributes, $this->extraData); } } diff --git a/tests/DocScan/SandboxClientTest.php b/tests/DocScan/SandboxClientTest.php index 4f1809c..b0479a2 100644 --- a/tests/DocScan/SandboxClientTest.php +++ b/tests/DocScan/SandboxClientTest.php @@ -46,7 +46,7 @@ function (RequestInterface $requestMessage) { ); $this->assertEquals('PUT', $requestMessage->getMethod()); - $this->assertRegExp($expectedPathPattern, (string)$requestMessage->getUri()); + $this->assertMatchesRegularExpression($expectedPathPattern, (string)$requestMessage->getUri()); return true; } ) @@ -89,7 +89,7 @@ function (RequestInterface $requestMessage) { ); $this->assertEquals('PUT', $requestMessage->getMethod()); - $this->assertRegExp($expectedPathPattern, (string)$requestMessage->getUri()); + $this->assertMatchesRegularExpression($expectedPathPattern, (string)$requestMessage->getUri()); return true; } ) diff --git a/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php b/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php new file mode 100644 index 0000000..461a384 --- /dev/null +++ b/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php @@ -0,0 +1,41 @@ +createMock(\JsonSerializable::class); + $valueMock->method('jsonSerialize')->willReturn('some-value'); + + $sandboxDataEntry = $this->getMockBuilder(SandboxDataEntry::class) + ->setConstructorArgs([self::SOME_TYPE, $valueMock]) + ->setMethodsExcept(['jsonSerialize']) + ->getMock(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'type' => self::SOME_TYPE, + 'value' => $valueMock, + ]), + json_encode($sandboxDataEntry) + ); + } +} diff --git a/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php b/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php new file mode 100644 index 0000000..39050f6 --- /dev/null +++ b/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php @@ -0,0 +1,40 @@ +createMock(SandboxDataEntry::class); + $dataEntryMock->method('jsonSerialize')->willReturn((object) ['some' => 'data-entry']); + + $extraData = (new SandboxExtraDataBuilder()) + ->withDataEntry($dataEntryMock) + ->build(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'data_entry' => [$dataEntryMock] + ]), + json_encode($extraData) + ); + } +} diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php new file mode 100644 index 0000000..0b5bde7 --- /dev/null +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php @@ -0,0 +1,59 @@ +withDefinition(self::SOME_DEFINITION) + ->withExpiryDate($someDateTime) + ->withIssuanceToken(self::SOME_TOKEN) + ->build(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'type' => self::TYPE_THIRD_PARTY_ATTRIBUTE, + 'value' => [ + 'issuance_token' => self::SOME_TOKEN, + 'issuing_attributes' => [ + 'expiry_date' => $someDateTime->format(\DateTime::RFC3339_EXTENDED), + 'definitions' => [ + [ + 'name' => self::SOME_DEFINITION, + ], + ], + ], + ], + ]), + json_encode($sandboxAttributeIssuanceDetails) + ); + } +} diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValueTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValueTest.php new file mode 100644 index 0000000..cbabcd1 --- /dev/null +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValueTest.php @@ -0,0 +1,41 @@ +createMock(SandboxIssuingAttributes::class); + $issuingAttributesMock + ->method('jsonSerialize') + ->willReturn((object) ['some' => 'issuing-attributes']); + + $value = new SandboxAttributeIssuanceDetailsValue(self::SOME_TOKEN, $issuingAttributesMock); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'issuance_token' => self::SOME_TOKEN, + 'issuing_attributes' => $issuingAttributesMock, + ]), + json_encode($value) + ); + } +} diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxDefinitionTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxDefinitionTest.php new file mode 100644 index 0000000..92e3203 --- /dev/null +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxDefinitionTest.php @@ -0,0 +1,34 @@ +assertJsonStringEqualsJsonString( + json_encode([ + 'name' => self::SOME_NAME, + ]), + json_encode($definition) + ); + } +} diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php new file mode 100644 index 0000000..65f8c9f --- /dev/null +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php @@ -0,0 +1,59 @@ +createMock(SandboxDefinition::class); + $definitionMock + ->method('jsonSerialize') + ->willReturn((object) ['some' => 'definition']); + + $someDateTime = DateTime::stringToDateTime($inputDate); + + $sandboxIssuingAttributes = new SandboxIssuingAttributes( + $someDateTime, + [$definitionMock] + ); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'expiry_date' => $outputDate, + 'definitions' => [$definitionMock], + ]), + json_encode($sandboxIssuingAttributes) + ); + } + + /** + * Provides test expiry dates. + */ + public function expiryDateDataProvider() + { + return [ + ['2020-01-02T01:02:03.123456Z', '2020-01-02T01:02:03.123+00:00'], + ['2020-01-01T01:02:03.123+04:00', '2019-12-31T21:02:03.123+00:00'], + ['2020-01-02T01:02:03.123-02:00', '2020-01-02T03:02:03.123+00:00'] + ]; + } +} diff --git a/tests/Profile/Request/TokenRequestBuilderTest.php b/tests/Profile/Request/TokenRequestBuilderTest.php index b2c072e..d508eca 100644 --- a/tests/Profile/Request/TokenRequestBuilderTest.php +++ b/tests/Profile/Request/TokenRequestBuilderTest.php @@ -7,6 +7,7 @@ use Yoti\Sandbox\Profile\Request\Attribute\SandboxAgeVerification; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAnchor; use Yoti\Sandbox\Profile\Request\Attribute\SandboxDocumentDetails; +use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraData; use Yoti\Sandbox\Profile\Request\TokenRequest; use Yoti\Sandbox\Profile\Request\TokenRequestBuilder; use Yoti\Sandbox\Test\TestCase; @@ -91,7 +92,6 @@ public function testStringAttributeSetters($setterMethod, $name) $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => $name, @@ -135,7 +135,6 @@ public function testStringAttributeSettersWithOptional($setterMethod, $name) $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => $name, @@ -173,7 +172,6 @@ public function testStringAttributeSettersWithAnchor($setterMethod, $name) $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => $name, @@ -217,7 +215,6 @@ public function testStringAttributeSettersWithOptionalAndAnchor($setterMethod, $ $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => $name, @@ -263,7 +260,6 @@ public function testSetDateOfBirth() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'date_of_birth', @@ -287,7 +283,6 @@ public function testSetSelfie() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'selfie', @@ -311,7 +306,6 @@ public function testSetSelfieWithAnchor() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'selfie', @@ -341,7 +335,6 @@ public function testSetSelfieWithOptionalAndAnchor() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'selfie', @@ -368,7 +361,6 @@ public function testSetDocumentDetails() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -395,7 +387,6 @@ public function testSetDocumentDetailsWithAnchor() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -428,7 +419,6 @@ public function testSetDocumentDetailsWithOptionalAndAnchor() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -452,7 +442,6 @@ public function testSetDocumentDetailsWithStringAndAnchors() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -482,7 +471,6 @@ public function testSetDocumentDetailsWithStringAndOptionalAndAnchors() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -512,10 +500,28 @@ public function testSetAgeVerification() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [$someAgeVerification] ]), json_encode($tokenRequest) ); } + + /** + * @covers ::setExtraData + */ + public function testSetExtraData() + { + $someExtraData = $this->createMock(SandboxExtraData::class); + $someExtraData->method('jsonSerialize')->willReturn((object) ['some' => 'extra-data']); + + $tokenRequest = $this->requestBuilder->setExtraData($someExtraData)->build(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'profile_attributes' => [], + 'extra_data' => $someExtraData, + ]), + json_encode($tokenRequest) + ); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 914e030..49626e3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,4 +8,21 @@ abstract class TestCase extends PHPUnitTestCase { + /** + * Override assertMatchesRegularExpression to support older versions of PHPUnit. + * + * @param string $pattern + * @param string $string + * @param string $message + * + * @return void + */ + public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void + { + if (method_exists(parent::class, __FUNCTION__)) { + parent::{__FUNCTION__}(...\func_get_args()); + } else { + parent::assertRegExp(...\func_get_args()); + } + } }