-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSplitTest.php
More file actions
58 lines (43 loc) · 2.02 KB
/
Copy pathSplitTest.php
File metadata and controls
58 lines (43 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace V2\FileOperations;
use Mindee\Input\LocalResponse;
use Mindee\Input\PathInput;
use Mindee\V2\FileOperations\Split;
use Mindee\V2\Product\Split\SplitResponse;
use PHPUnit\Framework\TestCase;
use TestingUtilities;
class SplitTest extends TestCase
{
private string $splitDataDir;
private string $finDocDataDir;
protected function setUp(): void
{
$this->splitDataDir = TestingUtilities::getV2DataDir() . '/products/split';
$this->finDocDataDir = TestingUtilities::getV2DataDir() . '/products/extraction/financial_document';
}
public function testProcessesSinglePageSplitCorrectly(): void
{
$inputSample = new PathInput($this->finDocDataDir . '/default_sample.jpg');
$localResponse = new LocalResponse($this->splitDataDir . '/split_single.json');
$doc = $localResponse->deserializeResponse(SplitResponse::class);
$splitOperation = new Split($inputSample);
$splits = $doc->inference->result->splits;
$extractedSplits = $splitOperation->extractMultipleSplits(array_map(static fn($s) => $s->pageRange, $splits));
self::assertCount(1, $extractedSplits);
self::assertSame(1, $extractedSplits[0]->getPageCount());
}
public function testProcessesMultiPageReceiptSplitCorrectly(): void
{
$inputSample = new PathInput($this->splitDataDir . '/invoice_5p.pdf');
$localResponse = new LocalResponse($this->splitDataDir . '/split_multiple.json');
$doc = $localResponse->deserializeResponse(SplitResponse::class);
$splitOperation = new Split($inputSample);
$splits = $doc->inference->result->splits;
$extractedSplits = $splitOperation->extractMultipleSplits(array_map(static fn($s) => $s->pageRange, $splits));
self::assertCount(3, $extractedSplits);
self::assertSame(1, $extractedSplits[0]->getPageCount());
self::assertSame(3, $extractedSplits[1]->getPageCount());
self::assertSame(1, $extractedSplits[2]->getPageCount());
}
}