|
| 1 | +<?php |
| 2 | + |
| 3 | +use veryfi\Client; |
| 4 | + |
| 5 | +require_once __DIR__ . '/ClientTestCase.php'; |
| 6 | + |
| 7 | +class ClientSplitDocumentsTest extends ClientTestCase |
| 8 | +{ |
| 9 | + public function test_get_split_documents(): void |
| 10 | + { |
| 11 | + if ($this->mock_responses) { |
| 12 | + $veryfi_client = $this->getMockBuilder(Client::class) |
| 13 | + ->onlyMethods(['exec_curl']) |
| 14 | + ->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key]) |
| 15 | + ->getMock(); |
| 16 | + |
| 17 | + $file_path = __DIR__ . '/resources/getDocuments.json'; |
| 18 | + $file = fopen($file_path, 'r'); |
| 19 | + $file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8'); |
| 20 | + $veryfi_client->expects($this->once()) |
| 21 | + ->method('exec_curl') |
| 22 | + ->willReturn($file_data); |
| 23 | + |
| 24 | + } else { |
| 25 | + $veryfi_client = new Client($this->client_id, $this->client_secret, $this->username, $this->api_key); |
| 26 | + } |
| 27 | + $json_response = json_decode($veryfi_client->get_split_documents(), true); |
| 28 | + $this->assertIsArray($json_response); |
| 29 | + } |
| 30 | + |
| 31 | + public function test_get_split_document(): void |
| 32 | + { |
| 33 | + if ($this->mock_responses) { |
| 34 | + $veryfi_client = $this->getMockBuilder(Client::class) |
| 35 | + ->onlyMethods(['exec_curl']) |
| 36 | + ->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key]) |
| 37 | + ->getMock(); |
| 38 | + |
| 39 | + $file_path = __DIR__ . '/resources/getDocument.json'; |
| 40 | + $file = fopen($file_path, 'r'); |
| 41 | + $file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8'); |
| 42 | + $veryfi_client->expects($this->once()) |
| 43 | + ->method('exec_curl') |
| 44 | + ->willReturn($file_data); |
| 45 | + $document_id = '125661908'; |
| 46 | + |
| 47 | + } else { |
| 48 | + $veryfi_client = new Client($this->client_id, $this->client_secret, $this->username, $this->api_key); |
| 49 | + $documents = json_decode($veryfi_client->get_split_documents(), true); |
| 50 | + if (isset($documents['documents'][0]['id'])) { |
| 51 | + $document_id = $documents['documents'][0]['id']; |
| 52 | + } else { |
| 53 | + $this->markTestSkipped('No documents found to test get_split_document'); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + $json_response = json_decode($veryfi_client->get_split_document($document_id), true); |
| 58 | + $this->assertEquals($document_id, $json_response['id']); |
| 59 | + } |
| 60 | + |
| 61 | + public function test_split_document_from_base64(): void |
| 62 | + { |
| 63 | + if ($this->mock_responses) { |
| 64 | + $veryfi_client = $this->getMockBuilder(Client::class) |
| 65 | + ->onlyMethods(['exec_curl']) |
| 66 | + ->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key]) |
| 67 | + ->getMock(); |
| 68 | + |
| 69 | + $file_path = __DIR__ . '/resources/processDocument.json'; |
| 70 | + $file = fopen($file_path, 'r'); |
| 71 | + $file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8'); |
| 72 | + $veryfi_client->expects($this->once()) |
| 73 | + ->method('exec_curl') |
| 74 | + ->willReturn($file_data); |
| 75 | + |
| 76 | + } else { |
| 77 | + $veryfi_client = new Client($this->client_id, $this->client_secret, $this->username, $this->api_key); |
| 78 | + } |
| 79 | + |
| 80 | + $file_path = $this->receipt_path; |
| 81 | + $file_name = 'receipt.jpg'; |
| 82 | + $base64_encoded_string = base64_encode(file_get_contents($file_path)); |
| 83 | + |
| 84 | + $json_response = json_decode($veryfi_client->split_document_from_base64($base64_encoded_string, $file_name), true); |
| 85 | + $this->assertIsArray($json_response); |
| 86 | + } |
| 87 | + |
| 88 | + public function test_split_document_from_url(): void |
| 89 | + { |
| 90 | + if ($this->mock_responses) { |
| 91 | + $veryfi_client = $this->getMockBuilder(Client::class) |
| 92 | + ->onlyMethods(['exec_curl']) |
| 93 | + ->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key]) |
| 94 | + ->getMock(); |
| 95 | + |
| 96 | + $file_path = __DIR__ . '/resources/processDocument.json'; |
| 97 | + $file = fopen($file_path, 'r'); |
| 98 | + $file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8'); |
| 99 | + $veryfi_client->expects($this->once()) |
| 100 | + ->method('exec_curl') |
| 101 | + ->willReturn($file_data); |
| 102 | + |
| 103 | + } else { |
| 104 | + $veryfi_client = new Client($this->client_id, $this->client_secret, $this->username, $this->api_key); |
| 105 | + } |
| 106 | + |
| 107 | + $url = 'https://raw.githubusercontent.com/veryfi/veryfi-python/master/tests/assets/receipt_public.jpg'; |
| 108 | + $json_response = json_decode($veryfi_client->split_document_from_url($url), true); |
| 109 | + $this->assertIsArray($json_response); |
| 110 | + } |
| 111 | +} |
0 commit comments