diff --git a/test/OnfidoTestCase.php b/test/OnfidoTestCase.php index b66cd37..0be369c 100644 --- a/test/OnfidoTestCase.php +++ b/test/OnfidoTestCase.php @@ -46,7 +46,7 @@ protected function createApplicant(): Onfido\Model\Applicant [ 'first_name' => 'Test', 'last_name' => 'Applicant', - 'dob' => new DateTime("1980-01-22"), + 'dob' => new DateTime('1980-01-22'), 'location' => new Onfido\Model\Location([ 'ip_address' => '127.0.0.1', 'country_of_residence' => Onfido\Model\CountryCodes::DEU @@ -86,6 +86,93 @@ protected static function cleanUpApplicants(): void } } } + + protected function uploadDocument(string $applicantId): Onfido\Model\Document + { + return self::$onfido->uploadDocument( + 'passport', + $applicantId, + new \SplFileObject('test/media/sample_driving_licence.png') + ); + } + + protected function uploadLivePhoto(string $applicantId): Onfido\Model\LivePhoto + { + return self::$onfido->uploadLivePhoto( + $applicantId, + new \SplFileObject('test/media/sample_photo.png') + ); + } + + protected function createCheck( + Onfido\Model\CheckBuilder $checkBuilder = null, + string $applicantId = null, + string $documentId = null, + array $reportNames = null + ): Onfido\Model\Check + { + if($checkBuilder != null) { + return self::$onfido->createCheck($checkBuilder); + } + + return self::$onfido->createCheck( + new Onfido\Model\CheckBuilder([ + 'applicant_id' => $applicantId, + 'document_ids' => [$documentId], + 'report_names' => $reportNames + ] + )); + } + + protected function createWorkflowRun( + Onfido\Model\WorkflowRunBuilder $workflowRunBuilder = null, + string $applicantId = null, + string $workflowId = null + ): Onfido\Model\WorkflowRun + { + if($workflowRunBuilder != null) { + return self::$onfido->createWorkflowRun($workflowRunBuilder); + } + + return self::$onfido->createWorkflowRun( + new Onfido\Model\WorkflowRunBuilder([ + 'applicant_id' => $applicantId, + 'workflow_id' => $workflowId + ]) + ); + } + + protected function getTaskIdByPartialId($tasks, string $partialId): string { + foreach ($tasks as $task) { + if (strpos($task->getId(), $partialId) !== false) { + return $task->getId(); + } + } + } + + protected function waitUntilStatus( + callable $function, + string $instanceId, + string $status, + $maxRetries = 10, + $sleepTime = 1 + ) + { + $instance = $function($instanceId); + $iteration = 0; + + while($instance->getStatus() !== $status) { + if($iteration > $maxRetries) { + $this->fail('Status did not change in time'); + } + + $iteration =+ 1; + sleep($sleepTime); + + $instance = $function($instanceId); + } + return $instance; + } } -?> \ No newline at end of file +?> diff --git a/test/Resource/AddressPickerTest.php b/test/Resource/AddressPickerTest.php new file mode 100644 index 0000000..866e82b --- /dev/null +++ b/test/Resource/AddressPickerTest.php @@ -0,0 +1,18 @@ +findAddresses($postCode)['addresses']; + $this->assertSame($postCode, $addressesWithPostCode[0]['postcode']); + } +} diff --git a/test/Resource/ApplicantsTest.php b/test/Resource/ApplicantsTest.php index 5d11dd3..36858c8 100644 --- a/test/Resource/ApplicantsTest.php +++ b/test/Resource/ApplicantsTest.php @@ -15,20 +15,17 @@ * @author OpenAPI Generator team * @link https://openapi-generator.tech */ -class ApplicantTest extends OnfidoTestCase +class ApplicantsTest extends OnfidoTestCase { + private $applicant; + private $applicantId; /** * Setup before running each test case */ public function setUp(): void { - } - - /** - * Clean up after running each test case - */ - public function tearDown(): void - { + $this->applicant = $this->createApplicant(); + $this->applicantId = $this->applicant->getId(); } /** @@ -36,15 +33,13 @@ public function tearDown(): void */ public function testCreateApplicant() { - $applicant = $this->createApplicant(); - - $this->assertSame('Test', $applicant->getFirstName()); - $this->assertSame('Applicant', $applicant->getLastName()); - $this->assertSame('1980-01-22', $applicant->getDob()->format('Y-m-d')); - $this->assertSame('127.0.0.1', $applicant->getLocation()->getIpAddress()); - $this->assertSame('DEU', $applicant->getLocation()->getCountryOfResidence()); + $this->assertSame('Test', $this->applicant->getFirstName()); + $this->assertSame('Applicant', $this->applicant->getLastName()); + $this->assertSame('1980-01-22', $this->applicant->getDob()->format('Y-m-d')); + $this->assertSame('127.0.0.1', $this->applicant->getLocation()->getIpAddress()); + $this->assertSame('DEU', $this->applicant->getLocation()->getCountryOfResidence()); - $address = $applicant->getAddress(); + $address = $this->applicant->getAddress(); $this->assertSame('100', $address->getBuildingNumber()); $this->assertSame('Main Street', $address->getStreet()); @@ -53,4 +48,45 @@ public function testCreateApplicant() $this->assertSame(Onfido\Model\CountryCodes::GBR, $address->getCountry()); $this->assertSame('My wonderful address', $address->getLine1()); } + + public function testListApplicants() + { + $listOfApplicants = self::$onfido->listApplicants()['applicants']; + $this->assertGreaterThan(0, sizeOf($listOfApplicants)); + } + + public function testFindApplicant() + { + $getApplicant = self::$onfido->findApplicant($this->applicantId); + + $this->assertSame($this->applicantId, $getApplicant->getId()); + } + + public function testUpdateApplicant() + { + $updatedApplicantData = new Onfido\Model\ApplicantBuilder([ + 'first_name' => 'Jane', + 'last_name' => 'Doe', + ]); + $updatedApplicant = self::$onfido->updateApplicant($this->applicantId, $updatedApplicantData); + $this->assertSame('Jane', $updatedApplicant->getFirstName()); + $this->assertSame('Doe', $updatedApplicant->getLastName()); + } + + public function testDeleteApplicant() + { + self::$onfido->deleteApplicant($this->applicantId); + + $this->expectException(Onfido\ApiException::class); + self::$onfido->findApplicant($this->applicantId); + } + + public function testRestoreDeleteApplicant() + { + self::$onfido->deleteApplicant($this->applicantId); + self::$onfido->restoreApplicant($this->applicantId); + $getApplicant = self::$onfido->findApplicant($this->applicantId); + + $this->assertSame($this->applicantId, $getApplicant->getId()); + } } diff --git a/test/Resource/ChecksTest.php b/test/Resource/ChecksTest.php new file mode 100644 index 0000000..2138e8e --- /dev/null +++ b/test/Resource/ChecksTest.php @@ -0,0 +1,97 @@ +applicantId = $this->createApplicant()->getId(); + $this->documentId = $this->uploadDocument($this->applicantId)->getId(); + $this->check = $this->createCheck( + null, + $this->applicantId, + $this->documentId, + [ReportName::DOCUMENT, ReportName::IDENTITY_ENHANCED] + ); + } + + public function testCreateCheck(): void + { + $this->assertSame($this->applicantId, $this->check->getApplicantId()); + $this->assertSame(Check::STATUS_IN_PROGRESS, $this->check->getStatus()); + $this->assertSame(2, sizeOf($this->check->getReportIds())); + } + + public function testCreateConsiderCheck(): void + { + $checkBuilder = new CheckBuilder([ + 'applicant_id' => $this->applicantId, + 'document_ids' => [$this->documentId], + 'report_names' => [ReportName::DOCUMENT], + 'consider' => [ReportName::DOCUMENT] + ]); + + $check = $this->createCheck($checkBuilder); + $this->assertSame($this->applicantId, $check->getApplicantId()); + } + + public function testCreateDrivingLicenceCheck(): void + { + $usDrivingLicenceBuilder = new UsDrivingLicenceBuilder([ + 'id_number' => '12345', + 'issue_state' => 'GA' + ]); + + $checkBuilder = new CheckBuilder([ + 'applicant_id' => $this->applicantId, + 'document_ids' => [$this->documentId], + 'report_names' => [ReportName::DOCUMENT], + 'us_driving_licence' => $usDrivingLicenceBuilder + ]); + + $check = $this->createCheck($checkBuilder); + + $this->assertSame($this->applicantId, $check->getApplicantId()); + } + + public function testListChecks(): void + { + $listOfChecks = self::$onfido->listChecks($this->applicantId)["checks"]; + + $this->assertGreaterThan(0, sizeOf($listOfChecks)); + } + + public function testFindCheck(): void + { + $getCheck = self::$onfido->findCheck($this->check->getId()); + + $this->assertSame($this->check->getId(), $getCheck->getId()); + $this->assertSame($this->applicantId, $getCheck->getApplicantId()); + } + + public function testRestartCheck(): void + { + self::$onfido->resumeCheck($this->check->getId()); + $this->assertTrue(true); + } + + public function testDownloadCheck(): void + { + $file = self::$onfido->downloadCheck($this->check->getId()); + + $this->assertGreaterThan(0, $file->getSize()); + } +} \ No newline at end of file diff --git a/test/Resource/DocumentsTest.php b/test/Resource/DocumentsTest.php new file mode 100644 index 0000000..9ba3bbe --- /dev/null +++ b/test/Resource/DocumentsTest.php @@ -0,0 +1,58 @@ +applicantId = $this->createApplicant()->getId(); + $this->document = $this->uploadDocument($this->applicantId); + } + + public function testUploadDocument(): void + { + $this->assertSame($this->applicantId, $this->document->getApplicantId()); + $this->assertSame(DocumentTypes::PASSPORT, $this->document->getType()); + $this->assertSame($this->applicantId, $this->document->getApplicantId()); + } + + public function testListDocuments(): void + { + $listOfDocuments = self::$onfido->listDocuments($this->applicantId)['documents']; + $this->assertGreaterThan(0, sizeOf($listOfDocuments)); + } + + public function testFindDocument(): void + { + $getDocument = self::$onfido->findDocument($this->document->getId()); + $this->assertSame($this->document->getId(), $getDocument->getId()); + } + + public function testDownloadDocument(): void + { + $file = self::$onfido->downloadDocument($this->document->getId()); + + $this->assertGreaterThan(0, $file->getSize()); + } + + public function testDownloadInexistentDocument(): void + { + $inexistentDocumentId = '00000000-0000-0000-0000-000000000000'; + + $this->expectException(Onfido\ApiException::class); + self::$onfido->downloadDocument($inexistentDocumentId); + } +} +?> \ No newline at end of file diff --git a/test/Resource/ExtractionTest.php b/test/Resource/ExtractionTest.php new file mode 100644 index 0000000..756a0f0 --- /dev/null +++ b/test/Resource/ExtractionTest.php @@ -0,0 +1,44 @@ +createApplicant()->getId(); + $this->documentId = $this->uploadDocument($applicantId)->getId(); + } + + public function testPerformExtraction(): void + { + $extraction = self::$onfido->extract(new ExtractRequest(['document_id' => $this->documentId])); + $this->assertSame($this->documentId, $extraction->getDocumentId()); + + $extractedData = $extraction->getExtractedData(); + $documentClassification = $extraction->getDocumentClassification(); + + $this->assertSame('SARAH', $extractedData->getFirstName()); + $this->assertSame('MORGAN', $extractedData->getLastName()); + $this->assertSame('Female', $extractedData->getGender()); + $this->assertSame('200407512345', $extractedData->getDocumentNumber(),); + $this->assertSame('1976-03-11', $extractedData->getDateOfBirth()->format('Y-m-d')); + $this->assertSame('2031-05-28', $extractedData->getDateOfExpiry()->format('Y-m-d')); + + $this->assertSame(DocumentTypes::DRIVING_LICENCE, $documentClassification->getDocumentType()); + $this->assertSame(CountryCodes::GBR, $documentClassification->getIssuingCountry()); + } +} + +?> diff --git a/test/Resource/LiveVideoTest.php b/test/Resource/LiveVideoTest.php new file mode 100644 index 0000000..54f07ff --- /dev/null +++ b/test/Resource/LiveVideoTest.php @@ -0,0 +1,54 @@ +applicantId = getenv('ONFIDO_SAMPLE_APPLICANT_ID'); + $this->liveVideoId = getenv('ONFIDO_SAMPLE_VIDEO_ID_1'); + } + + public function testDownloadLiveVideo() + { + $file = self::$onfido->downloadLiveVideo($this->liveVideoId); + + $this->assertGreaterThan(0, $file->getSize()); + } + + public function testDownloadInexistentLiveVideo() + { + $inexistentLiveVideoId = "00000000-0000-0000-0000-000000000000"; + + $this->expectException(ApiException::class); + self::$onfido->downloadLiveVideo($inexistentLiveVideoId); + } + + public function testDownloadLiveVideoFrame() + { + $file = self::$onfido->downloadLiveVideoFrame($this->liveVideoId); + + $this->assertGreaterThan(0, $file->getSize()); + } + + public function testFindLiveVideo() + { + $getLiveVideo = self::$onfido->findLiveVideo($this->liveVideoId); + + $this->assertSame($this->liveVideoId, $getLiveVideo->getId()); + } + + public function testListLiveVideos() + { + $listOfLiveVideos = self::$onfido->listLiveVideos($this->applicantId)['live_videos']; + + $this->assertGreaterThan(0, sizeOf($listOfLiveVideos)); + } +} diff --git a/test/Resource/MotionCaptureTest.php b/test/Resource/MotionCaptureTest.php new file mode 100644 index 0000000..49fc670 --- /dev/null +++ b/test/Resource/MotionCaptureTest.php @@ -0,0 +1,55 @@ +applicantId = getenv('ONFIDO_SAMPLE_APPLICANT_ID'); + $this->motionCaptureId = getenv('ONFIDO_SAMPLE_MOTION_ID_1'); + } + + public function testDownloadMotionCapture() + { + $file = self::$onfido->downloadMotionCapture($this->motionCaptureId); + + $this->assertGreaterThan(0, $file->getSize()); + } + + public function testDownloadInexistentMotionCapture() + { + $inexistentMotionCaptureId = "00000000-0000-0000-0000-000000000000"; + + $this->expectException(ApiException::class); + self::$onfido->downloadMotionCapture($inexistentMotionCaptureId); + } + + public function testDownloadMotionCaptureFrame() + { + $file = self::$onfido->downloadMotionCaptureFrame($this->motionCaptureId); + + $this->assertGreaterThan(0, $file->getSize()); + } + + public function testFindMotionCapture() + { + $getMotionCapture = self::$onfido->findMotionCapture($this->motionCaptureId); + + $this->assertSame($this->motionCaptureId, $getMotionCapture->getId()); + } + + public function testListMotionCaptures() + { + $listOfMotionCaptures = self::$onfido->listMotionCaptures($this->applicantId)['motion_captures']; + + $this->assertGreaterThan(0, sizeOf($listOfMotionCaptures)); + } +} diff --git a/test/Resource/ReportSchemasTest.php b/test/Resource/ReportSchemasTest.php new file mode 100644 index 0000000..49e3815 --- /dev/null +++ b/test/Resource/ReportSchemasTest.php @@ -0,0 +1,67 @@ +applicantId = $this->createApplicant()->getId(); + $this->documentId = $this->uploadDocument($this->applicantId); + $this->findReportFn = function($reportId) { + return self::$onfido->findReport($reportId); + }; + } + + public function testSchemaOfDocumentReportIsValid(): void + { + $documentReportId = $this->createCheck( + null, + $this->applicantId, + $this->documentId, + [ReportName::DOCUMENT] + )->getReportIds()[0]; + + $documentReport = $this->waitUntilStatus( + $this->findReportFn, + $documentReportId, + ReportStatus::COMPLETE + )->getActualInstance(); + + $this->assertInstanceOf(DocumentReport::class, $documentReport); + } + + public function testSchemaOfFacialSimilarityReportIsValid(): void + { + $this->uploadLivePhoto($this->applicantId); + $facialSimilarityReportId = $this->createCheck( + null, + $this->applicantId, + $this->documentId, + [ReportName::FACIAL_SIMILARITY_PHOTO] + )->getReportIds()[0]; + + $facialSimilarityReport = $this->waitUntilStatus( + $this->findReportFn, + $facialSimilarityReportId, + ReportStatus::COMPLETE + )->getActualInstance(); + + $this->assertInstanceOf( + FacialSimilarityPhotoReport::class, + $facialSimilarityReport + ); + } +} + +?> \ No newline at end of file diff --git a/test/Resource/ReportsTest.php b/test/Resource/ReportsTest.php new file mode 100644 index 0000000..ad7ba37 --- /dev/null +++ b/test/Resource/ReportsTest.php @@ -0,0 +1,74 @@ +createApplicant()->getId(); + $documentId = $this->uploadDocument($applicantId)->getId(); + $check = $this->createCheck( + null, + $applicantId, + $documentId, + [ReportName::DOCUMENT, ReportName::IDENTITY_ENHANCED] + ); + $this->sortedReports = $this->sortReports(self::$onfido->listReports($check->getId())['reports']); + $this->documentReportId = $this->sortedReports[0]->getId(); + $this->identityReportId = $this->sortedReports[1]->getId(); + } + + public function sortReports($reportList): array + { + usort($reportList, function($a, $b) { + return strcmp($a->getName(), $b->getName()); + }); + + return $reportList; + } + + public function testListReports(): void + { + $this->assertSame(ReportName::DOCUMENT, $this->sortedReports[0]->getName()); + $this->assertSame(ReportName::IDENTITY_ENHANCED, $this->sortedReports[1]->getName()); + } + + public function testFindReport(): void + { + $getDocumentReport = self::$onfido->findReport($this->documentReportId); + $getIdentityReport = self::$onfido->findReport($this->identityReportId); + + $this->assertSame($this->documentReportId, $getDocumentReport->getId()); + $this->assertSame(ReportName::DOCUMENT, $getDocumentReport->getName()); + $this->assertSame(ReportStatus::AWAITING_DATA, $getDocumentReport->getStatus()); + + $this->assertSame($this->identityReportId, $getIdentityReport->getId()); + $this->assertSame(ReportName::IDENTITY_ENHANCED, $getIdentityReport->getName()); + $this->assertSame(ReportStatus::COMPLETE, $getIdentityReport->getStatus()); + } + + public function testResumeReport(): void + { + self::$onfido->resumeReport($this->documentReportId); + $this->assertTrue(true); + } + + public function testCancelReport(): void + { + self::$onfido->cancelReport($this->documentReportId); + $this->assertTrue(true); + } + } + +?> diff --git a/test/Resource/SdkTokenTest.php b/test/Resource/SdkTokenTest.php new file mode 100644 index 0000000..fbf17a7 --- /dev/null +++ b/test/Resource/SdkTokenTest.php @@ -0,0 +1,30 @@ +applicantId = $this->createApplicant()->getId(); + } + + public function testGenerateSdkToken(): void + { + $token = self::$onfido->generateSdkToken( + new SdkTokenBuilder(['applicant_id' => $this->applicantId]) + )['token']; + + $this->assertGreaterThan(0, strlen($token)); + } +} + +?> \ No newline at end of file diff --git a/test/Resource/TasksTest.php b/test/Resource/TasksTest.php new file mode 100644 index 0000000..ff45096 --- /dev/null +++ b/test/Resource/TasksTest.php @@ -0,0 +1,54 @@ +createApplicant()->getId(); + $workflowId = 'e8c921eb-0495-44fe-b655-bcdcaffdafe5'; + $this->workflowRunId = $this->createWorkflowRun(null, $applicantId, $workflowId)->getId(); + } + + public function testListTasks(): void + { + $listOfTasks = self::$onfido->listTasks($this->workflowRunId); + $this->assertGreaterThan(0, sizeOf($listOfTasks)); + } + + public function testFindTask(): void + { + $task = self::$onfido->listTasks($this->workflowRunId)[0]; + $getTask = self::$onfido->findTask($this->workflowRunId, $task->getId()); + + $this->assertSame($task->getId(), $getTask->getId()); + $this->assertSame($task->getTaskDefId(), $getTask->getTaskDefId()); + } + + public function testCompleteTask(): void + { + $tasks = self::$onfido->listTasks($this->workflowRunId); + $profileDataTaskId = $this->getTaskIdByPartialId($tasks, 'profile'); + + $completeTaskBuilder = new CompleteTaskBuilder(['data' => [ + 'first_name' => 'Jane', + 'last_name' => 'Doe' + ]]); + + self::$onfido->completeTask($this->workflowRunId, $profileDataTaskId, $completeTaskBuilder); + $taskOutputs = self::$onfido->findTask($this->workflowRunId, $profileDataTaskId) + ->getOutput(); + + $this->assertSame('Jane', $taskOutputs['first_name']); + $this->assertSame('Doe', $taskOutputs['last_name']); + } +} + +?> diff --git a/test/Resource/WatchlistMonitorTest.php b/test/Resource/WatchlistMonitorTest.php new file mode 100644 index 0000000..374118b --- /dev/null +++ b/test/Resource/WatchlistMonitorTest.php @@ -0,0 +1,97 @@ +applicantId = $this->createApplicant()->getId(); + $this->watchlistMonitor = self::$onfido->createWatchlistMonitor( + new WatchlistMonitorBuilder([ + 'applicant_id' => $this->applicantId, + 'report_name' => WatchlistMonitorBuilder::REPORT_NAME_STANDARD + ]) + ); + } + + public function testCreateWatchlistStandardMonitor(): void + { + $this->assertSame($this->applicantId, $this->watchlistMonitor->getApplicantId()); + $this->assertSame( + WatchlistMonitorBuilder::REPORT_NAME_STANDARD, + $this->watchlistMonitor->getReportName() + ); + } + + public function testCreateWatchlistAmlMonitor(): void + { + $applicantId = $this->createApplicant()->getId(); + $watchlistAmlMonitor = self::$onfido->createWatchlistMonitor( + new WatchlistMonitorBuilder([ + 'applicant_id' => $applicantId, + 'report_name' => WatchlistMonitorBuilder::REPORT_NAME_AML + ]) + ); + + $this->assertSame($applicantId, $watchlistAmlMonitor->getApplicantId()); + $this->assertSame( + WatchlistMonitorBuilder::REPORT_NAME_AML, + $watchlistAmlMonitor->getReportName() + ); + } + + public function testListWatchlistMonitors(): void + { + $listOfWatchlistMonitors = self::$onfido->listWatchlistMonitors( + $this->applicantId + )['monitors']; + + $this->assertGreaterThan(0, sizeOf($listOfWatchlistMonitors)); + } + + public function testFindWatchlistMonitor(): void + { + $getWatchlistMonitor = self::$onfido->findWatchlistMonitor( + $this->watchlistMonitor->getId() + ); + + $this->assertSame($this->watchlistMonitor->getId(), $getWatchlistMonitor->getId()); + } + + public function testDeleteWatchlistMonitor(): void + { + self::$onfido->deleteWatchlistMonitor( + $this->watchlistMonitor->getId() + ); + + $this->assertTrue(true); + } + + public function testListWatchlistMonitorMatches(): void + { + $listOfWatchlistMonitorMatches = self::$onfido->listWatchlistMonitorMatches( + $this->watchlistMonitor->getId() + )['matches']; + + $this->assertEquals(0, sizeOf($listOfWatchlistMonitorMatches)); + } + + public function testForceReportCreation(): void + { + self::$onfido->forceReportCreationFromWatchlistMonitor( + $this->watchlistMonitor->getId() + ); + + $checks = self::$onfido->listChecks($this->applicantId)['checks']; + $this->assertEquals(2, sizeOf($checks)); + } +} + +?> \ No newline at end of file diff --git a/test/Resource/WorkflowRunOutputsTest.php b/test/Resource/WorkflowRunOutputsTest.php new file mode 100644 index 0000000..45a6a28 --- /dev/null +++ b/test/Resource/WorkflowRunOutputsTest.php @@ -0,0 +1,146 @@ +applicantId = $this->createApplicant()->getId(); + $this->profileData = [ + 'country_residence' => 'GBR', + 'first_name' => 'First', + 'last_name' => 'Last', + 'dob' => '2000-01-01', + 'email' => 'first.last@gmail.com', + 'phone_number' => '+351911111111', + 'nationality' => 'GBR', + 'phone_number_consent_granted' => true, + 'address' => [ + 'country' => 'GBR', + 'line1' => '123rd Street', + 'line2' => '2nd Floor', + 'line3' => '23', + 'town' => 'London', + 'postcode' => 'S2 2DF', + ], + ]; + + $this->documentId = $this->uploadDocument($this->applicantId)->getId(); + $this->livePhotoId = $this->uploadLivePhoto($this->applicantId)->getId(); + $this->findWorkflowRunFn = function($workflowRunId) { + return self::$onfido->findWorkflowRun($workflowRunId); + }; + } + + public function testProfileDataCaptureAsOutput(): void + { + $workflowId = 'd27e510b-27a8-44c3-a3cc-bf4c0648a4ba'; + $workflowRunId = $this->createWorkflowRun(null, $this->applicantId, $workflowId)->getId(); + + $tasks = self::$onfido->listTasks($workflowRunId); + $profileDataTaskId = $this->getTaskIdByPartialId($tasks, 'profile'); + $completeTaskBuilder = new CompleteTaskBuilder(['data' => $this->profileData]); + + self::$onfido->completeTask($workflowRunId, $profileDataTaskId, $completeTaskBuilder); + $workflowRunOutputs = $this->waitUntilStatus( + $this->findWorkflowRunFn, + $workflowRunId, + WorkflowRun::STATUS_APPROVED + )->getOutput(); + + // Can't compare output with profileData directly due to issues with types, + // so converting the output into array and comparing key by key value + // (without the address which also causes issues and is compared separately) + $keysExceptAddress = array_filter(array_keys($this->profileData), + function($key) { + return $key !== 'address'; + } + ); + + foreach($keysExceptAddress as $key) { + $this->assertEquals( + $this->profileData[$key], + ((array) $workflowRunOutputs['profile_capture_data'])[$key] + ); + } + + $this->assertEquals( + $this->profileData['address'], + (array) ((array) $workflowRunOutputs['profile_capture_data'])['address'] + ); + } + + public function testDocumentAndFacialSimilarityReportAsOutput() + { + $workflowId = '5025d9fd-7842-4805-bce1-a7bfd7131b4e'; + $workflowRunId = $this->createWorkflowRun(null, $this->applicantId, $workflowId)->getId(); + + $tasks = self::$onfido->listTasks($workflowRunId); + $profileDataTaskId = $this->getTaskIdByPartialId($tasks, 'profile'); + self::$onfido->completeTask( + $workflowRunId, + $profileDataTaskId, + new CompleteTaskBuilder(['data' => [ + 'first_name' => 'First', + 'last_name' => 'Last' + ]]) + ); + + $tasks = self::$onfido->listTasks($workflowRunId); + $documentCaptureTaskId = $this->getTaskIdByPartialId($tasks, 'document'); + self::$onfido->completeTask( + $workflowRunId, + $documentCaptureTaskId, + new CompleteTaskBuilder(['data' => [[ + 'id' => $this->documentId + ]]]) + ); + + $tasks = self::$onfido->listTasks($workflowRunId); + $documentCaptureTaskId = $this->getTaskIdByPartialId($tasks, 'face_photo'); + self::$onfido->completeTask( + $workflowRunId, + $documentCaptureTaskId, + new CompleteTaskBuilder(['data' => [[ + 'id' => $this->livePhotoId + ]]]) + ); + + $workflowRunOutputs = $this->waitUntilStatus( + $this->findWorkflowRunFn, + $workflowRunId, + WorkflowRun::STATUS_APPROVED + )->getOutput(); + + $documentReportOutput = (array) $workflowRunOutputs['doc']; + $facialSimilarityReportOutput = (array) $workflowRunOutputs['selfie']; + + $this->assertNotNull($documentReportOutput['breakdown']); + $this->assertNotNull($documentReportOutput['properties']); + $this->assertNotNull($documentReportOutput['repeat_attempts']); + $this->assertNotNull($documentReportOutput['result']); + $this->assertNotNull($documentReportOutput['status']); + $this->assertNotNull($documentReportOutput['sub_result']); + $this->assertNotNull($documentReportOutput['uuid']); + + $this->assertNotNull($facialSimilarityReportOutput['breakdown']); + $this->assertNotNull($facialSimilarityReportOutput['properties']); + $this->assertNotNull($facialSimilarityReportOutput['result']); + $this->assertNotNull($facialSimilarityReportOutput['status']); + $this->assertNotNull($facialSimilarityReportOutput['uuid']); + } +} + +?> \ No newline at end of file diff --git a/test/Resource/WorkflowRunsTest.php b/test/Resource/WorkflowRunsTest.php new file mode 100644 index 0000000..2a91832 --- /dev/null +++ b/test/Resource/WorkflowRunsTest.php @@ -0,0 +1,65 @@ +applicantId = $this->createApplicant()->getId(); + $this->workflowId = 'e8c921eb-0495-44fe-b655-bcdcaffdafe5'; + $this->workflowRun = $this->createWorkflowRun(null, $this->applicantId, $this->workflowId); + } + + public function testCreateWorkflowRun(): void + { + $this->assertSame($this->workflowId, $this->workflowRun->getWorkflowId()); + $this->assertSame(WorkflowRun::STATUS_AWAITING_INPUT, $this->workflowRun->getStatus()); + } + + public function testCreateWorkflowRunWithCustomInputs(): void + { + $workflowId = '45092b29-f220-479e-aa6f-a6f989baac4c'; + $workflowRunBuilder = new WorkflowRunBuilder([ + 'applicant_id' => $this->applicantId, + 'workflow_id' => $workflowId, + 'custom_data' => [ + 'age' => 18, + 'is_employed' => false + ] + ]); + + $workflowRun = $this->createWorkflowRun($workflowRunBuilder); + + $this->assertSame($workflowId, $workflowRun->getWorkflowId()); + $this->assertSame(WorkflowRun::STATUS_APPROVED, $workflowRun->getStatus()); + } + + public function testListWorkflowRuns(): void + { + $listOfWorkflowRuns = self::$onfido->listWorkflowRuns(); + $this->assertGreaterThan(0, sizeOf($listOfWorkflowRuns)); + } + + public function testFindWorkflowRun(): void + { + $getWorkflowRun = self::$onfido->findWorkflowRun($this->workflowRun->getId()); + $this->assertSame($this->workflowRun->getId(), $getWorkflowRun->getId()); + } + + public function testDownloadEvidenceFile(): void + { + $file = self::$onfido->downloadSignedEvidenceFile($this->workflowRun->getId()); + $this->assertGreaterThan(0, $file->getSize()); + } +} + +?> \ No newline at end of file diff --git a/test/media/sample_driving_licence.png b/test/media/sample_driving_licence.png new file mode 100644 index 0000000..07bb4fe Binary files /dev/null and b/test/media/sample_driving_licence.png differ diff --git a/test/media/sample_photo.png b/test/media/sample_photo.png new file mode 100644 index 0000000..240349f Binary files /dev/null and b/test/media/sample_photo.png differ