Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/4.3.1 #372

Merged
merged 10 commits into from
Sep 12, 2024
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
},
Expand Down
82 changes: 69 additions & 13 deletions tests/DocScan/DocScanClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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' ]);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
32 changes: 19 additions & 13 deletions tests/YotiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down
Loading