From 9f9b977c5f0701483d02c8e1be443ab15ded8499 Mon Sep 17 00:00:00 2001 From: mehmet-yoti <111424390+mehmet-yoti@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:52:04 +0300 Subject: [PATCH] Release/4.3.1 (#372) * Sdk 2481 Library Updates (Fix for psr/http-message version error on php 8)(#369) --- README.md | 4 +- composer.json | 4 +- examples/digitalidentity/.env.example | 2 +- src/Constants.php | 2 +- tests/DocScan/DocScanClientTest.php | 82 ++++++++++++++++++++++----- tests/YotiClientTest.php | 32 ++++++----- 6 files changed, 94 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 6f35b579..49577e1f 100755 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ Add the Yoti SDK dependency: ```json "require": { - "yoti/yoti-php-sdk" : "^4.3.0" + "yoti/yoti-php-sdk" : "^4.3.1" } ``` Or run this Composer command ```console -$ composer require yoti/yoti-php-sdk "^4.3.0" +$ composer require yoti/yoti-php-sdk "^4.3.1" ``` ## Setup diff --git a/composer.json b/composer.json index 420fe8e3..cf053fa2 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "yoti/yoti-php-sdk", "description": "Yoti SDK for quickly integrating your PHP backend with Yoti", - "version": "4.3.0", + "version": "4.3.1", "keywords": [ "yoti", "sdk" @@ -15,7 +15,7 @@ "phpseclib/phpseclib": "^3.0", "guzzlehttp/guzzle": "^7.0", "psr/http-client": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^2.0", "guzzlehttp/psr7": "^2.4", "ext-openssl": "*" }, diff --git a/examples/digitalidentity/.env.example b/examples/digitalidentity/.env.example index 72022df2..58bc3f2e 100644 --- a/examples/digitalidentity/.env.example +++ b/examples/digitalidentity/.env.example @@ -1,4 +1,4 @@ -# This file is a template for defining the environment variables +0# This file is a template for defining the environment variables # Set the application config values here YOTI_SDK_ID=xxxxxxxxxxxxxxxxxxxxx diff --git a/src/Constants.php b/src/Constants.php index b1cb4499..ac625f8f 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -31,7 +31,7 @@ class Constants public const SDK_IDENTIFIER = 'PHP'; /** Default SDK version */ - public const SDK_VERSION = '4.3.0'; + public const SDK_VERSION = '4.3.1'; /** Base url for connect page (user will be redirected to this page eg. baseurl/app-id) */ public const CONNECT_BASE_URL = 'https://www.yoti.com/connect'; diff --git a/tests/DocScan/DocScanClientTest.php b/tests/DocScan/DocScanClientTest.php index 306e1d17..623c0a60 100644 --- a/tests/DocScan/DocScanClientTest.php +++ b/tests/DocScan/DocScanClientTest.php @@ -6,6 +6,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; use Yoti\DocScan\DocScanClient; use Yoti\DocScan\Session\Create\CreateSessionResult; use Yoti\DocScan\Session\Create\FaceCapture\CreateFaceCaptureResourcePayload; @@ -92,8 +93,12 @@ public function testEmptyApiUrlEnvironmentVariable() */ private function assertApiUrlStartsWith($expectedUrl, $clientApiUrl = null) { + $stream = $this->createMock(\Psr\Http\Message\StreamInterface::class); + $stream->method('getContents')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE)); + $stream->method('__toString')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE)); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE)); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -126,8 +131,13 @@ private function assertApiUrlStartsWith($expectedUrl, $clientApiUrl = null) */ public function testCreateSession() { + $stream = $this->createMock(\Psr\Http\Message\StreamInterface::class); + $stream->method('getContents')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE)); + $stream->method('__toString')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE)); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE)); + $response->method('getBody')->willReturn($stream); + $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -155,8 +165,12 @@ public function testCreateSession() */ public function testGetSession() { + $stream = $this->createMock(\Psr\Http\Message\StreamInterface::class); + $stream->method('getContents')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE)); + $stream->method('__toString')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE)); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE)); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -203,8 +217,13 @@ public function testDeleteSessionDoesNotThrowException() */ public function testGetMedia() { + $stream = $this->createMock(\Psr\Http\Message\StreamInterface::class); + $stream->method('getContents')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE)); + $stream->method('__toString')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE)); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE)); + $response->method('getBody')->willReturn($stream); + $response->method('getStatusCode')->willReturn(200); $response->method('getHeader')->willReturn([ 'image/png' ]); @@ -276,8 +295,12 @@ public function testDeleteMediaDoesNotThrowException() */ public function testGetSupportedDocuments() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(json_encode((object)[])); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -301,8 +324,12 @@ public function testGetSupportedDocuments() */ public function testCreateFaceCaptureResource() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(json_encode((object)[])); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(201); $createFaceCaptureResourcePayloadMock = $this->createMock(CreateFaceCaptureResourcePayload::class); @@ -331,9 +358,14 @@ public function testCreateFaceCaptureResource() */ public function testUploadFaceCaptureImage() { + + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); + $response->method('getBody')->willReturn($stream); $uploadFaceCaptureImagePayloadMock = $this->createMock(UploadFaceCaptureImagePayload::class); - $response->method('getBody')->willReturn(json_encode((object)[])); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -358,8 +390,12 @@ public function testUploadFaceCaptureImage() */ public function testGetSessionConfiguration() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(json_encode((object)[])); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -383,9 +419,13 @@ public function testGetSessionConfiguration() */ public function testPutIbvInstructions() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); + $response->method('getBody')->willReturn($stream); $instructionsMock = $this->createMock(Instructions::class); - $response->method('getBody')->willReturn(json_encode((object)[])); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -409,8 +449,12 @@ public function testPutIbvInstructions() */ public function testGetIbvInstructions() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(json_encode((object)[])); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -433,8 +477,12 @@ public function testGetIbvInstructions() */ public function testGetIbvInstructionsPdf() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(json_encode((object)[])); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -457,8 +505,12 @@ public function testGetIbvInstructionsPdf() */ public function testFetchInstructionsContactProfile() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(json_encode((object)[])); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -481,8 +533,12 @@ public function testFetchInstructionsContactProfile() */ public function testTriggerIbvEmailNotification() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(json_encode((object)[])); + $stream->method('__toString')->willReturn(json_encode((object)[])); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(json_encode((object)[])); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); diff --git a/tests/YotiClientTest.php b/tests/YotiClientTest.php index 9f345a5a..d95b635f 100755 --- a/tests/YotiClientTest.php +++ b/tests/YotiClientTest.php @@ -7,6 +7,7 @@ use GuzzleHttp\Psr7; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; use Psr\Log\LoggerInterface; use Yoti\Aml\Address as AmlAddress; use Yoti\Aml\Country as AmlCountry; @@ -122,8 +123,12 @@ private function assertApiUrlStartsWith($expectedUrl, $clientApiUrl = null) */ public function testGetActivityDetails() { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(file_get_contents(TestData::RECEIPT_JSON)); + $stream->method('__toString')->willReturn(file_get_contents(TestData::RECEIPT_JSON)); + $response = $this->createMock(ResponseInterface::class); - $response->method('getBody')->willReturn(file_get_contents(TestData::RECEIPT_JSON)); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); $httpClient = $this->createMock(ClientInterface::class); @@ -220,20 +225,21 @@ public function testGetLoginUrl() */ public function testCustomLogger() { - $response = $this->createMock(ResponseInterface::class); + $jsonstr = json_encode([ + 'receipt' => [ + 'timestamp' => 'some invalid timestamp', + 'wrapped_receipt_key' => 'some receipt key', + 'sharing_outcome' => 'SUCCESS', + ] + ]); + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn($jsonstr); + $stream->method('__toString')->willReturn($jsonstr); + + $response = $this->createMock(ResponseInterface::class); + $response->method('getBody')->willReturn($stream); $response->method('getStatusCode')->willReturn(200); - $response - ->method('getBody') - ->willReturn( - json_encode([ - 'receipt' => [ - 'timestamp' => 'some invalid timestamp', - 'wrapped_receipt_key' => 'some receipt key', - 'sharing_outcome' => 'SUCCESS', - ] - ]) - ); $httpClient = $this->createMock(ClientInterface::class); $httpClient->expects($this->exactly(1))