Skip to content

Commit

Permalink
Add missing unit tests
Browse files Browse the repository at this point in the history
Update missing unit tests
Update to version 1.0.4
  • Loading branch information
alejouribesanchez committed Sep 25, 2024
1 parent e96a75e commit 024734a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
23 changes: 17 additions & 6 deletions src/veryfi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
declare(strict_types=1);
namespace veryfi;


use CurlHandle;
use Exception;

/**
Expand All @@ -21,7 +19,7 @@ class Client
*
* @var array static.
*/
const array CATEGORIES = [
const CATEGORIES = [
'Advertising & Marketing',
'Automotive',
'Bank Charges & Fees',
Expand Down Expand Up @@ -132,7 +130,7 @@ public function __construct(string $client_id,
private function get_headers(): array
{
return array(
'User-Agent' => 'php veryfi-php/1.0.3',
'User-Agent' => 'php veryfi-php/1.0.4',
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Client-ID' => $this->client_id,
Expand Down Expand Up @@ -213,10 +211,10 @@ private function request(string $http_verb,
/**\internal
* Exec the curl, needed for mock it.
*
* @param CurlHandle $curl Curl handle of request.
* @param $curl Curl handle of request.
* @return string A JSON response.
*/
protected function exec_curl(CurlHandle $curl): string
protected function exec_curl($curl): string
{
return curl_exec($curl);
}
Expand Down Expand Up @@ -570,6 +568,19 @@ public function get_w2_documents(int $page = null): string
return $this->request('GET', $endpoint_name, $params);
}

/**
* Get a W2 document.
*
* @param string $document_id The ID of the document you'd like to retrieve.
* @return string Data extracted from the document.
*/
public function get_w2_document(string $document_id): string
{
$endpoint_name = "/w2s/{$document_id}/";
$request_arguments = ['id' => $document_id];
return $this->request('GET', $endpoint_name, $request_arguments);
}

/**
* Process a W2 document from a file path and extract all fields from it.
*
Expand Down
27 changes: 18 additions & 9 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ClientTest extends TestCase
private string $w2_path = __DIR__ . '/resources/w2.png';
private string $any_doc_path = __DIR__ . '/resources/driver_license.png';
private string $bank_statement_path = __DIR__ . '/resources/bankstatement.pdf';
private bool $mock_responses = false;
private bool $mock_responses = true;

protected function setUp(): void
{
Expand Down Expand Up @@ -558,7 +558,7 @@ public function test_process_any_document(): void
$file_path = __DIR__ .'/resources/processAnyDocument.json';
$file = fopen($file_path, 'r');
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
$veryfi_client->expects($this->once())
$veryfi_client->expects($this->atLeastOnce())
->method('exec_curl')
->willReturn($file_data);

Expand All @@ -584,7 +584,7 @@ public function test_process_bank_statement(): void
$file_path = __DIR__ .'/resources/processBankStatement.json';
$file = fopen($file_path, 'r');
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
$veryfi_client->expects($this->once())
$veryfi_client->expects($this->atLeastOnce())
->method('exec_curl')
->willReturn($file_data);

Expand All @@ -607,7 +607,7 @@ public function test_process_any_document_url(): void
->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key])
->getMock();

$file_path = __DIR__ . '/resources/processAnyDocumentUrl.json';
$file_path = __DIR__ . '/resources/processAnyDocument.json';
$file = fopen($file_path, 'r');
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
$veryfi_client->expects($this->once())
Expand All @@ -631,7 +631,7 @@ public function test_process_bank_statement_url(): void
->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key])
->getMock();

$file_path = __DIR__ . '/resources/processBankStatementUrl.json';
$file_path = __DIR__ . '/resources/processBankStatement.json';
$file = fopen($file_path, 'r');
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
$veryfi_client->expects($this->once())
Expand All @@ -654,7 +654,7 @@ public function test_process_w2_document_from_url(): void
->onlyMethods(['exec_curl'])
->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key])
->getMock();
$file_path = __DIR__ . '/resources/processW2DocumentFromUrl.json';
$file_path = __DIR__ . '/resources/processW2Document.json';
$file = fopen($file_path, 'r');
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
$veryfi_client->expects($this->once())
Expand Down Expand Up @@ -684,7 +684,7 @@ public function test_get_w2_documents(): void
$file_path = __DIR__ . '/resources/getW2Documents.json';
$file = fopen($file_path, 'r');
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
$veryfi_client->expects($this->once())
$veryfi_client->expects($this->atLeastOnce())
->method('exec_curl')
->willReturn($file_data);

Expand All @@ -694,6 +694,9 @@ public function test_get_w2_documents(): void
$json_response = json_decode($veryfi_client->get_w2_documents(), true);
$json_len = sizeof($json_response);
$this->assertTrue($json_len > 1);
$document_id = $json_response['results'][0]['id'];
$json_response = json_decode($veryfi_client->get_w2_document($document_id), true);
$this->assertNotEmpty( $json_response);
}

public function test_get_bank_statements(): void
Expand All @@ -707,7 +710,7 @@ public function test_get_bank_statements(): void
$file_path = __DIR__ . '/resources/getBankStatements.json';
$file = fopen($file_path, 'r');
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
$veryfi_client->expects($this->once())
$veryfi_client->expects($this->atLeastOnce())
->method('exec_curl')
->willReturn($file_data);

Expand All @@ -718,6 +721,9 @@ public function test_get_bank_statements(): void
$json_response = json_decode($veryfi_client->get_bank_statements(), true);
$json_len = sizeof($json_response);
$this->assertTrue($json_len > 1);
$document_id = $json_response['results'][0]['id'];
$json_response = json_decode($veryfi_client->get_bank_statement($document_id), true);
$this->assertNotEmpty( $json_response);
}

public function test_get_any_documents(): void
Expand All @@ -731,7 +737,7 @@ public function test_get_any_documents(): void
$file_path = __DIR__ . '/resources/getAnyDocuments.json';
$file = fopen($file_path, 'r');
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
$veryfi_client->expects($this->once())
$veryfi_client->expects($this->atLeastOnce())
->method('exec_curl')
->willReturn($file_data);

Expand All @@ -742,5 +748,8 @@ public function test_get_any_documents(): void
$json_response = json_decode($veryfi_client->get_any_documents(), true);
$json_len = sizeof($json_response);
$this->assertTrue($json_len > 1);
$document_id = $json_response['results'][0]['id'];
$json_response = json_decode($veryfi_client->get_any_document($document_id), true);
$this->assertNotEmpty( $json_response);
}
}

0 comments on commit 024734a

Please sign in to comment.