Skip to content

Commit e33cd41

Browse files
♻️ uniformize tests with other libs
1 parent 737c734 commit e33cd41

82 files changed

Lines changed: 304 additions & 850 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/CustomSleepMixin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ trait CustomSleepMixin
66
{
77
/**
88
* Waits for a custom amount of time from either a float or an integer.
9+
* Purposefully waits for one more millisecond on windows due to flakiness in delays between OS.
910
* @param float|integer $delay Delay in seconds.
1011
* @return void
1112
*/

src/Parsing/DependencyChecker.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public static function isImageMagickPolicyAllowed(): void
9090
$imagick = new \Imagick();
9191
try {
9292
$imagick->readImage(
93-
(getenv('GITHUB_WORKSPACE') ?: ".") .
94-
"/tests/resources/products/expense_receipts/default_sample.jpg"
93+
\TestingUtilities::getV1DataDir() . "/products/expense_receipts/default_sample.jpg"
9594
);
9695
} catch (\Exception $e) {
9796
throw new MindeeUnhandledException(

tests/ClientTest.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,23 @@ class ClientTest extends TestCase
2121
private Client $dummyClient;
2222
private Client $envClient;
2323
private string $oldKey;
24-
private string $fileTypesDir;
2524
private string $multiReceiptsDetectorPath;
2625
private string $failedJobPath;
2726

2827

2928
protected function setUp(): void
3029
{
31-
$rootPath = (getenv('GITHUB_WORKSPACE') ?: ".");
3230
$this->oldKey = getenv('MINDEE_API_KEY');
3331
$this->dummyClient = new Client("dummy-key");
3432
putenv('MINDEE_API_KEY=');
3533
$this->emptyClient = new Client();
3634
putenv('MINDEE_API_KEY=dummy-env-key');
3735
$this->envClient = new Client();
38-
$this->fileTypesDir = (
39-
$rootPath . "/tests/resources/file_types/"
40-
);
4136
$this->multiReceiptsDetectorPath = (
42-
$rootPath . "/tests/resources/products/multi_receipts_detector/response_v1/complete.json"
37+
\TestingUtilities::getV1DataDir() . "/products/multi_receipts_detector/response_v1/complete.json"
4338
);
4439
$this->failedJobPath = (
45-
$rootPath . "/tests/resources/async/get_failed_job_error.json"
40+
\TestingUtilities::getV1DataDir() . "/async/get_failed_job_error.json"
4641
);
4742
}
4843

@@ -56,37 +51,37 @@ public function testParsePathWithoutToken()
5651
{
5752
$this->expectException(MindeeHttpClientException::class);
5853

59-
$inputDoc = $this->emptyClient->sourceFromPath($this->fileTypesDir . "pdf/blank.pdf");
54+
$inputDoc = $this->emptyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
6055
$this->emptyClient->parse(InvoiceV4::class, $inputDoc);
6156
}
6257

6358
public function testParsePathWithEnvToken()
6459
{
6560
$this->expectException(MindeeHttpException::class);
6661

67-
$inputDoc = $this->envClient->sourceFromPath($this->fileTypesDir . "pdf/blank.pdf");
62+
$inputDoc = $this->envClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
6863
$this->envClient->parse(InvoiceV4::class, $inputDoc);
6964
}
7065

7166
public function testParsePathWithWrongFileType()
7267
{
7368
$this->expectException(Mindee\Error\MindeeMimeTypeException::class);
7469

75-
$inputDoc = $this->dummyClient->sourceFromPath($this->fileTypesDir . "receipt.txt");
70+
$inputDoc = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() ."/receipt.txt");
7671
}
7772

7873
public function testParsePathWithWrongToken()
7974
{
8075
$this->expectException(MindeeHttpClientException::class);
8176

82-
$inputDoc = $this->dummyClient->sourceFromPath($this->fileTypesDir . "pdf/blank.pdf");
77+
$inputDoc = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
8378
$this->dummyClient->parse(InvoiceV4::class, $inputDoc);
8479
}
8580

8681
public function testInterfaceVersion()
8782
{
8883
$dummyEndpoint = $this->dummyClient->createEndpoint("dummy", "dummy", "1.1");
89-
$inputDoc = $this->dummyClient->sourceFromPath($this->fileTypesDir . "pdf/blank.pdf");
84+
$inputDoc = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
9085
$predictOptions = new PredictMethodOptions();
9186
$this->assertEquals("1.1", $dummyEndpoint->settings->version);
9287

@@ -100,7 +95,7 @@ public function testInterfaceVersion()
10095

10196
public function testCutOptions()
10297
{
103-
$inputDoc = $this->dummyClient->sourceFromPath($this->fileTypesDir . "pdf/multipage.pdf");
98+
$inputDoc = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf");
10499
$this->expectException(MindeeHttpClientException::class);
105100
$pageOptions = new PageOptions(range(0, 4));
106101
$this->dummyClient->parse(ReceiptV5::class, $inputDoc, null, $pageOptions);
@@ -138,7 +133,7 @@ public function testPredictOptionsValidInputType()
138133
{
139134
$predictOptions = new PredictMethodOptions();
140135
$this->assertTrue($predictOptions->pageOptions->isEmpty());
141-
$inputDoc = $this->dummyClient->sourceFromPath($this->fileTypesDir . "pdf/blank.pdf");
136+
$inputDoc = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
142137
$this->expectException(MindeeHttpClientException::class);
143138
$this->dummyClient->parse(InvoiceV4::class, $inputDoc, $predictOptions);
144139
$this->expectException(MindeeHttpClientException::class);

tests/Parsing/DependencyCheckerNoExtendedTestPdf.php renamed to tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ class DependencyCheckerNoExtendedTestPdf extends TestCase
1313
public function testNoImageExtractor()
1414
{
1515
$this->expectException(MindeeUnhandledException::class);
16-
$inputObj = new PathInput((getenv('GITHUB_WORKSPACE') ?: "."
17-
) . "/tests/resources/file_types/pdf/blank.pdf");
16+
$inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
1817
new ImageExtractor($inputObj);
1918
}
2019
public function testNoPdfExtractor()
2120
{
2221
$this->expectException(MindeeUnhandledException::class);
23-
$inputObj = new PathInput((getenv('GITHUB_WORKSPACE') ?: "."
24-
) . "/tests/resources/file_types/pdf/blank.pdf");
22+
$inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
2523
new PdfExtractor($inputObj);
2624
}
2725
public function testNoExtractedImage()

tests/Parsing/DependencyCheckerPdfTest.php renamed to tests/Dependencies/DependencyCheckerPdfTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Parsing;
3+
namespace Dependencies;
44

55
use Mindee\Parsing\DependencyChecker;
66
use PHPUnit\Framework\TestCase;

0 commit comments

Comments
 (0)