Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CustomSleepMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ trait CustomSleepMixin
{
/**
* Waits for a custom amount of time from either a float or an integer.
* Purposefully waits for one more millisecond on windows due to flakiness in delays between OS.
* @param float|integer $delay Delay in seconds.
* @return void
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Parsing/DependencyChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public static function isImageMagickPolicyAllowed(): void
$imagick = new \Imagick();
try {
$imagick->readImage(
(getenv('GITHUB_WORKSPACE') ?: ".") .
"/tests/resources/products/expense_receipts/default_sample.jpg"
\TestingUtilities::getV1DataDir() . "/products/expense_receipts/default_sample.jpg"
);
} catch (\Exception $e) {
throw new MindeeUnhandledException(
Expand Down
23 changes: 9 additions & 14 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,23 @@ class ClientTest extends TestCase
private Client $dummyClient;
private Client $envClient;
private string $oldKey;
private string $fileTypesDir;
private string $multiReceiptsDetectorPath;
private string $failedJobPath;


protected function setUp(): void
{
$rootPath = (getenv('GITHUB_WORKSPACE') ?: ".");
$this->oldKey = getenv('MINDEE_API_KEY');
$this->dummyClient = new Client("dummy-key");
putenv('MINDEE_API_KEY=');
$this->emptyClient = new Client();
putenv('MINDEE_API_KEY=dummy-env-key');
$this->envClient = new Client();
$this->fileTypesDir = (
$rootPath . "/tests/resources/file_types/"
);
$this->multiReceiptsDetectorPath = (
$rootPath . "/tests/resources/products/multi_receipts_detector/response_v1/complete.json"
\TestingUtilities::getV1DataDir() . "/products/multi_receipts_detector/response_v1/complete.json"
);
$this->failedJobPath = (
$rootPath . "/tests/resources/async/get_failed_job_error.json"
\TestingUtilities::getV1DataDir() . "/async/get_failed_job_error.json"
);
}

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

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

public function testParsePathWithEnvToken()
{
$this->expectException(MindeeHttpException::class);

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

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

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

public function testParsePathWithWrongToken()
{
$this->expectException(MindeeHttpClientException::class);

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

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

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

public function testCutOptions()
{
$inputDoc = $this->dummyClient->sourceFromPath($this->fileTypesDir . "pdf/multipage.pdf");
$inputDoc = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf");
$this->expectException(MindeeHttpClientException::class);
$pageOptions = new PageOptions(range(0, 4));
$this->dummyClient->parse(ReceiptV5::class, $inputDoc, null, $pageOptions);
Expand Down Expand Up @@ -138,7 +133,7 @@ public function testPredictOptionsValidInputType()
{
$predictOptions = new PredictMethodOptions();
$this->assertTrue($predictOptions->pageOptions->isEmpty());
$inputDoc = $this->dummyClient->sourceFromPath($this->fileTypesDir . "pdf/blank.pdf");
$inputDoc = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
$this->expectException(MindeeHttpClientException::class);
$this->dummyClient->parse(InvoiceV4::class, $inputDoc, $predictOptions);
$this->expectException(MindeeHttpClientException::class);
Expand Down
4 changes: 3 additions & 1 deletion tests/ClientV2TestFunctional.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function testParseFileEmptyMultiPageMustSucceed(): void
*/
public function testParseFileFilledSinglePageMustSucceed(): void
{
$source = new PathInput(__DIR__ . '/resources/products/financial_document/default_sample.jpg');
$source = new PathInput(
TestingUtilities::getV1DataDir() . '/products/financial_document/default_sample.jpg'
);

$inferenceParams = new InferenceParameters($this->modelId, rag: false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Dependencies;

use Mindee\Error\MindeeUnhandledException;
use Mindee\Extraction\ExtractedImage;
use Mindee\Extraction\ExtractedPdf;
Expand All @@ -8,20 +10,20 @@
use Mindee\Input\PathInput;
use PHPUnit\Framework\TestCase;

require_once(__DIR__ . "/../TestingUtilities.php");

class DependencyCheckerNoExtendedTestPdf extends TestCase
{
public function testNoImageExtractor()
{
$this->expectException(MindeeUnhandledException::class);
$inputObj = new PathInput((getenv('GITHUB_WORKSPACE') ?: "."
) . "/tests/resources/file_types/pdf/blank.pdf");
$inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
new ImageExtractor($inputObj);
}
public function testNoPdfExtractor()
{
$this->expectException(MindeeUnhandledException::class);
$inputObj = new PathInput((getenv('GITHUB_WORKSPACE') ?: "."
) . "/tests/resources/file_types/pdf/blank.pdf");
$inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
new PdfExtractor($inputObj);
}
public function testNoExtractedImage()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Parsing;
namespace Dependencies;

use Mindee\Parsing\DependencyChecker;
use PHPUnit\Framework\TestCase;
Expand Down
Loading