From e33cd41acaf62ac063d1d9818e283627c52ad375 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Thu, 13 Nov 2025 11:01:24 +0100 Subject: [PATCH 1/4] :recycle: uniformize tests with other libs --- src/CustomSleepMixin.php | 1 + src/Parsing/DependencyChecker.php | 3 +- tests/ClientTest.php | 23 ++- .../DependencyCheckerNoExtendedTestPdf.php | 6 +- .../DependencyCheckerPdfTest.php | 2 +- tests/Input/LocalInputSourceTest.php | 148 ++++++++---------- tests/Input/LocalResponseTest.php | 2 +- tests/Input/URLInputSourceTest.php | 4 - .../BarcodeReaderV1TestRegression.php | 34 ---- .../Cropper/CropperV1TestRegression.php | 34 ---- .../FinancialDocumentV1TestRegression.php | 34 ---- .../BankAccountDetailsV1TestRegression.php | 34 ---- .../BankAccountDetailsV2TestRegression.php | 34 ---- .../CarteGrise/CarteGriseV1TestRegression.php | 34 ---- .../HealthCard/HealthCardV1TestRegression.php | 34 ---- .../Fr/IdCard/IdCardV1TestRegression.php | 34 ---- .../Fr/IdCard/IdCardV2TestRegression.php | 34 ---- .../Invoice/InvoiceV4TestRegression.php | 34 ---- .../InvoiceSplitterV1TestRegression.php | 34 ---- .../MultiReceiptsDetectorV1TestRegression.php | 34 ---- .../Passport/PassportV1TestRegression.php | 34 ---- tests/Product/ProductSharedData.php | 11 -- .../Receipt/ReceiptV5TestRegression.php | 34 ---- .../BankCheck/BankCheckV1TestRegression.php | 34 ---- tests/TestingUtilities.php | 31 ++++ tests/{ => V1}/CLI/MindeeCLICommandTest.php | 6 +- .../CLI/MindeeCLICommandTestFunctional.php | 10 +- .../CLI/MindeeCLITestingUtilities.php | 2 +- .../Error/MindeeHttpExceptionTest.php | 6 +- .../Extraction/ImageExtractorTest.php | 52 +++--- ...ceSplitterAutoExtractionTestFunctional.php | 7 +- .../{ => V1}/Extraction/PdfExtractorTest.php | 11 +- tests/{ => V1}/Http/MindeeApiTest.php | 3 +- .../Input/URLInputSourceTestFunctional.php | 14 +- .../Common/AsyncPredictResponseTest.php | 4 +- .../Common/Extras/CropperExtraTest.php | 8 +- .../Extras/ExtrasIntegrationFunctional.php | 6 +- .../Common/Extras/FullTextOcrExtraTest.php | 4 +- tests/{ => V1}/Parsing/Common/Ocr/OcrTest.php | 10 +- .../Parsing/Common/PredictResponseTest.php | 6 +- .../BarcodeReader/BarcodeReaderV1Test.php | 7 +- .../BillOfLading/BillOfLadingV1Test.php | 7 +- .../BusinessCard/BusinessCardV1Test.php | 7 +- .../Product/Cropper/CropperV1Test.php | 6 +- .../DeliveryNote/DeliveryNoteV1Test.php | 7 +- .../DriverLicense/DriverLicenseV1Test.php | 7 +- .../FinancialDocumentV1Test.php | 6 +- .../BankAccountDetailsV1Test.php | 7 +- .../BankAccountDetailsV2Test.php | 7 +- .../Fr/CarteGrise/CarteGriseV1Test.php | 7 +- .../Fr/EnergyBill/EnergyBillV1Test.php | 7 +- .../Fr/HealthCard/HealthCardV1Test.php | 7 +- .../Product/Fr/IdCard/IdCardV1Test.php | 6 +- .../Product/Fr/IdCard/IdCardV2Test.php | 6 +- .../Product/Fr/Payslip/PayslipV2Test.php | 7 +- .../Product/Fr/Payslip/PayslipV3Test.php | 7 +- .../Product/Generated/GeneratedV1Test.php | 23 ++- .../IndianPassport/IndianPassportV1Test.php | 7 +- .../InternationalId/InternationalIdV2Test.php | 7 +- .../Product/Invoice/InvoiceV4Test.php | 7 +- .../InvoiceSplitter/InvoiceSplitterV1Test.php | 7 +- .../MultiReceiptsDetectorV1Test.php | 7 +- .../NutritionFactsLabelV1Test.php | 7 +- .../Product/Passport/PassportV1Test.php | 7 +- .../Product/Receipt/ReceiptV5Test.php | 7 +- .../{ => V1}/Product/Resume/ResumeV1Test.php | 7 +- .../Product/Us/BankCheck/BankCheckV1Test.php | 6 +- .../HealthcareCard/HealthcareCardV1Test.php | 7 +- .../Product/Us/UsMail/UsMailV3Test.php | 7 +- .../Standard/AmountFieldTest.php | 2 +- .../Standard/ClassificationFieldTest.php | 2 +- .../Standard/CompanyRegistrationFieldTest.php | 2 +- .../Standard/DateFieldTest.php | 2 +- .../Standard/LocaleFieldTest.php | 2 +- .../Standard/PaymentDetailsFieldTest.php | 2 +- .../Standard/PositionFieldTest.php | 2 +- .../Standard/StringFieldTest.php | 2 +- tests/{Parsing => V1}/Standard/TaxesTest.php | 4 +- tests/{ => V1}/Workflow/WorkflowTest.php | 8 +- .../Workflow/WorkflowTestFunctional.php | 7 +- tests/{Parsing => }/V2/InferenceTest.php | 13 +- tests/resources | 2 +- 82 files changed, 304 insertions(+), 850 deletions(-) rename tests/{Parsing => Dependencies}/DependencyCheckerNoExtendedTestPdf.php (81%) rename tests/{Parsing => Dependencies}/DependencyCheckerPdfTest.php (96%) delete mode 100644 tests/Product/BarcodeReader/BarcodeReaderV1TestRegression.php delete mode 100644 tests/Product/Cropper/CropperV1TestRegression.php delete mode 100644 tests/Product/FinancialDocument/FinancialDocumentV1TestRegression.php delete mode 100644 tests/Product/Fr/BankAccountDetails/BankAccountDetailsV1TestRegression.php delete mode 100644 tests/Product/Fr/BankAccountDetails/BankAccountDetailsV2TestRegression.php delete mode 100644 tests/Product/Fr/CarteGrise/CarteGriseV1TestRegression.php delete mode 100644 tests/Product/Fr/HealthCard/HealthCardV1TestRegression.php delete mode 100644 tests/Product/Fr/IdCard/IdCardV1TestRegression.php delete mode 100644 tests/Product/Fr/IdCard/IdCardV2TestRegression.php delete mode 100644 tests/Product/Invoice/InvoiceV4TestRegression.php delete mode 100644 tests/Product/InvoiceSplitter/InvoiceSplitterV1TestRegression.php delete mode 100644 tests/Product/MultiReceiptsDetector/MultiReceiptsDetectorV1TestRegression.php delete mode 100644 tests/Product/Passport/PassportV1TestRegression.php delete mode 100644 tests/Product/ProductSharedData.php delete mode 100644 tests/Product/Receipt/ReceiptV5TestRegression.php delete mode 100644 tests/Product/Us/BankCheck/BankCheckV1TestRegression.php rename tests/{ => V1}/CLI/MindeeCLICommandTest.php (88%) rename tests/{ => V1}/CLI/MindeeCLICommandTestFunctional.php (85%) rename tests/{ => V1}/CLI/MindeeCLITestingUtilities.php (97%) rename tests/{ => V1}/Error/MindeeHttpExceptionTest.php (95%) rename tests/{ => V1}/Extraction/ImageExtractorTest.php (63%) rename tests/{ => V1}/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php (92%) rename tests/{ => V1}/Extraction/PdfExtractorTest.php (83%) rename tests/{ => V1}/Http/MindeeApiTest.php (98%) rename tests/{ => V1}/Input/URLInputSourceTestFunctional.php (76%) rename tests/{ => V1}/Parsing/Common/AsyncPredictResponseTest.php (97%) rename tests/{ => V1}/Parsing/Common/Extras/CropperExtraTest.php (91%) rename tests/{ => V1}/Parsing/Common/Extras/ExtrasIntegrationFunctional.php (86%) rename tests/{ => V1}/Parsing/Common/Extras/FullTextOcrExtraTest.php (93%) rename tests/{ => V1}/Parsing/Common/Ocr/OcrTest.php (84%) rename tests/{ => V1}/Parsing/Common/PredictResponseTest.php (82%) rename tests/{ => V1}/Product/BarcodeReader/BarcodeReaderV1Test.php (87%) rename tests/{ => V1}/Product/BillOfLading/BillOfLadingV1Test.php (93%) rename tests/{ => V1}/Product/BusinessCard/BusinessCardV1Test.php (90%) rename tests/{ => V1}/Product/Cropper/CropperV1Test.php (92%) rename tests/{ => V1}/Product/DeliveryNote/DeliveryNoteV1Test.php (89%) rename tests/{ => V1}/Product/DriverLicense/DriverLicenseV1Test.php (91%) rename tests/{ => V1}/Product/FinancialDocument/FinancialDocumentV1Test.php (96%) rename tests/{ => V1}/Product/Fr/BankAccountDetails/BankAccountDetailsV1Test.php (87%) rename tests/{ => V1}/Product/Fr/BankAccountDetails/BankAccountDetailsV2Test.php (89%) rename tests/{ => V1}/Product/Fr/CarteGrise/CarteGriseV1Test.php (94%) rename tests/{ => V1}/Product/Fr/EnergyBill/EnergyBillV1Test.php (92%) rename tests/{ => V1}/Product/Fr/HealthCard/HealthCardV1Test.php (88%) rename tests/{ => V1}/Product/Fr/IdCard/IdCardV1Test.php (93%) rename tests/{ => V1}/Product/Fr/IdCard/IdCardV2Test.php (94%) rename tests/{ => V1}/Product/Fr/Payslip/PayslipV2Test.php (95%) rename tests/{ => V1}/Product/Fr/Payslip/PayslipV3Test.php (95%) rename tests/{ => V1}/Product/Generated/GeneratedV1Test.php (93%) rename tests/{ => V1}/Product/Ind/IndianPassport/IndianPassportV1Test.php (92%) rename tests/{ => V1}/Product/InternationalId/InternationalIdV2Test.php (91%) rename tests/{ => V1}/Product/Invoice/InvoiceV4Test.php (94%) rename tests/{ => V1}/Product/InvoiceSplitter/InvoiceSplitterV1Test.php (86%) rename tests/{ => V1}/Product/MultiReceiptsDetector/MultiReceiptsDetectorV1Test.php (86%) rename tests/{ => V1}/Product/NutritionFactsLabel/NutritionFactsLabelV1Test.php (94%) rename tests/{ => V1}/Product/Passport/PassportV1Test.php (91%) rename tests/{ => V1}/Product/Receipt/ReceiptV5Test.php (91%) rename tests/{ => V1}/Product/Resume/ResumeV1Test.php (92%) rename tests/{ => V1}/Product/Us/BankCheck/BankCheckV1Test.php (93%) rename tests/{ => V1}/Product/Us/HealthcareCard/HealthcareCardV1Test.php (91%) rename tests/{ => V1}/Product/Us/UsMail/UsMailV3Test.php (90%) rename tests/{Parsing => V1}/Standard/AmountFieldTest.php (96%) rename tests/{Parsing => V1}/Standard/ClassificationFieldTest.php (96%) rename tests/{Parsing => V1}/Standard/CompanyRegistrationFieldTest.php (96%) rename tests/{Parsing => V1}/Standard/DateFieldTest.php (97%) rename tests/{Parsing => V1}/Standard/LocaleFieldTest.php (97%) rename tests/{Parsing => V1}/Standard/PaymentDetailsFieldTest.php (98%) rename tests/{Parsing => V1}/Standard/PositionFieldTest.php (98%) rename tests/{Parsing => V1}/Standard/StringFieldTest.php (98%) rename tests/{Parsing => V1}/Standard/TaxesTest.php (94%) rename tests/{ => V1}/Workflow/WorkflowTest.php (94%) rename tests/{ => V1}/Workflow/WorkflowTestFunctional.php (91%) rename tests/{Parsing => }/V2/InferenceTest.php (97%) diff --git a/src/CustomSleepMixin.php b/src/CustomSleepMixin.php index 9c7cd0cd..614ed6f9 100644 --- a/src/CustomSleepMixin.php +++ b/src/CustomSleepMixin.php @@ -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 */ diff --git a/src/Parsing/DependencyChecker.php b/src/Parsing/DependencyChecker.php index 6cb19b3e..39b1ea81 100644 --- a/src/Parsing/DependencyChecker.php +++ b/src/Parsing/DependencyChecker.php @@ -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( diff --git a/tests/ClientTest.php b/tests/ClientTest.php index f2239a2a..959870c4 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -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" ); } @@ -56,7 +51,7 @@ 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); } @@ -64,7 +59,7 @@ 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); } @@ -72,21 +67,21 @@ 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); @@ -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); @@ -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); diff --git a/tests/Parsing/DependencyCheckerNoExtendedTestPdf.php b/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php similarity index 81% rename from tests/Parsing/DependencyCheckerNoExtendedTestPdf.php rename to tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php index 87056eb8..583698a3 100644 --- a/tests/Parsing/DependencyCheckerNoExtendedTestPdf.php +++ b/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php @@ -13,15 +13,13 @@ 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() diff --git a/tests/Parsing/DependencyCheckerPdfTest.php b/tests/Dependencies/DependencyCheckerPdfTest.php similarity index 96% rename from tests/Parsing/DependencyCheckerPdfTest.php rename to tests/Dependencies/DependencyCheckerPdfTest.php index 24e2aa7c..ff3f59b3 100644 --- a/tests/Parsing/DependencyCheckerPdfTest.php +++ b/tests/Dependencies/DependencyCheckerPdfTest.php @@ -1,6 +1,6 @@ oldKey = getenv(API_KEY_ENV_NAME); $this->dummyClient = new Client("dummy-key"); putenv(API_KEY_ENV_NAME . '='); - $this->fileTypesDir = ( - getenv('GITHUB_WORKSPACE') ?: "." - ) . "/tests/resources/file_types/"; - $this->productsDir = ( - getenv('GITHUB_WORKSPACE') ?: "." - ) . "/tests/resources/products/"; - $this->outputDir = ( - getenv('GITHUB_WORKSPACE') ?: "." - ) . "/tests/resources/output/"; } protected function tearDown(): void @@ -52,20 +40,20 @@ protected function tearDown(): void putenv(API_KEY_ENV_NAME . '=' . $this->oldKey); $filesToDelete = [ - $this->outputDir . "/compress_indirect.jpg", - $this->outputDir . "/compress100.jpg", - $this->outputDir . "/compress85.jpg", - $this->outputDir . "/compress50.jpg", - $this->outputDir . "/compress10.jpg", - $this->outputDir . "/compress1.jpg", - $this->outputDir . "/not_compressed.pdf", - $this->outputDir . "/compress_indirect.pdf", - $this->outputDir . "/not_compressed_multipage.pdf", - $this->outputDir . "/compress_direct_85.pdf", - $this->outputDir . "/compress_direct_75.pdf", - $this->outputDir . "/compress_direct_50.pdf", - $this->outputDir . "/compress_direct_10.pdf", - $this->outputDir . "/text_multipage.pdf" + \TestingUtilities::getRootDataDir() . "/output/compress_indirect.jpg", + \TestingUtilities::getRootDataDir() . "/output/compress100.jpg", + \TestingUtilities::getRootDataDir() . "/output/compress85.jpg", + \TestingUtilities::getRootDataDir() . "/output/compress50.jpg", + \TestingUtilities::getRootDataDir() . "/output/compress10.jpg", + \TestingUtilities::getRootDataDir() . "/output/compress1.jpg", + \TestingUtilities::getRootDataDir() . "/output/not_compressed.pdf", + \TestingUtilities::getRootDataDir() . "/output/compress_indirect.pdf", + \TestingUtilities::getRootDataDir() . "/output/not_compressed_multipage.pdf", + \TestingUtilities::getRootDataDir() . "/output/compress_direct_85.pdf", + \TestingUtilities::getRootDataDir() . "/output/compress_direct_75.pdf", + \TestingUtilities::getRootDataDir() . "/output/compress_direct_50.pdf", + \TestingUtilities::getRootDataDir() . "/output/compress_direct_10.pdf", + \TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf" ]; foreach ($filesToDelete as $file) { @@ -78,20 +66,20 @@ protected function tearDown(): void public function testPDFCountPages() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $this->assertEquals(12, $inputObj->getPageCount()); } public function testPDFReconstructOK() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], KEEP_ONLY, 2)); $this->assertEquals(5, $inputObj->getPageCount()); } public function testPDFReadContents() { - $inputDoc = new PathInput($this->fileTypesDir . "/pdf/multipage.pdf"); + $inputDoc = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $contents = $inputDoc->readContents(); $this->assertEquals("multipage.pdf", $contents[0]); } @@ -101,13 +89,13 @@ public function testPDFReadContents() */ public function testPDFCutNPages(array $indexes) { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions($indexes, KEEP_ONLY, 2)); try { $basePdf = new FPDI(); $cutPdf = new FPDI(); $pageCountCutPdf = $cutPdf->setSourceFile( - $this->fileTypesDir . "pdf/multipage_cut-" . count($indexes) . ".pdf" + \TestingUtilities::getFileTypesDir() . "/pdf/multipage_cut-" . count($indexes) . ".pdf" ); $pageCountBasePdf = $basePdf->setSourceFile($inputObj->fileObject->getFilename()); $basePdf->Close(); @@ -118,7 +106,7 @@ public function testPDFCutNPages(array $indexes) $basePdf = new FPDI(); $cutPdf = new FPDI(); for ($pageNumber = 0; $pageNumber < $pageCountBasePdf; $pageNumber++) { - $cutPdf->setSourceFile($this->fileTypesDir . "pdf/multipage_cut-" . count($indexes) . ".pdf"); + $cutPdf->setSourceFile(\TestingUtilities::getFileTypesDir() . "/pdf/multipage_cut-" . count($indexes) . ".pdf"); $basePdf->setSourceFile($inputObj->fileObject->getFilename()); $cutPdf->AddPage(); $cutPdf->useTemplate($cutPdf->importPage($pageNumber + 1)); @@ -146,14 +134,14 @@ public function pageIndexesProvider() public function testPDFKeep5FirstPages() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], KEEP_ONLY, 2)); $this->assertEquals(5, $inputObj->getPageCount()); } public function testPDFKeepInvalidPages() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([0, 1, 17], KEEP_ONLY, 2)); $this->assertEquals(2, $inputObj->getPageCount()); } @@ -161,35 +149,35 @@ public function testPDFKeepInvalidPages() public function testPDFRemove5LastPages() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([-5, -4, -3, -2, -1], REMOVE, 2)); $this->assertEquals(7, $inputObj->getPageCount()); } public function testPDFRemove5FirstPages() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], REMOVE, 2)); $this->assertEquals(7, $inputObj->getPageCount()); } public function testPDFRemoveInvalidPages() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputObj->applyPageOptions(new PageOptions([16], REMOVE, 2)); $this->assertEquals(12, $inputObj->getPageCount()); } public function testPDFKeepNoPages() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $this->expectException(MindeePDFException::class); $inputObj->applyPageOptions(new PageOptions([], KEEP_ONLY, 2)); } public function testPDFRemoveAllPages() { - $inputObj = new PathInput($this->fileTypesDir . "pdf/multipage.pdf"); + $inputObj = new PathInput(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $this->expectException(MindeePDFException::class); $pageOptions = new PageOptions(range(0, $inputObj->getPageCount() - 1), REMOVE, 2); $inputObj->applyPageOptions(pageOptions: $pageOptions); @@ -197,8 +185,8 @@ public function testPDFRemoveAllPages() public function testPDFInputFromFile() { - $fileContents = file_get_contents($this->fileTypesDir . "/pdf/multipage.pdf"); - $fileRef = fopen($this->fileTypesDir . "/pdf/multipage.pdf", "r"); + $fileContents = file_get_contents(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $fileRef = fopen(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf", "r"); $inputDoc = new FileInput($fileRef); $contents = $inputDoc->readContents(); $this->assertEquals("multipage.pdf", $contents[0]); @@ -207,7 +195,7 @@ public function testPDFInputFromFile() public function testPDFInputFromBytes() { - $pdfBytes = file_get_contents($this->fileTypesDir . "/pdf/multipage.pdf"); + $pdfBytes = file_get_contents(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $inputDoc = new BytesInput($pdfBytes, "dummy.pdf"); $contents = $inputDoc->readContents(); $this->assertEquals("dummy.pdf", $contents[0]); @@ -216,7 +204,7 @@ public function testPDFInputFromBytes() public function testInputFromRawb64String() { - $pdfBytes = file_get_contents($this->fileTypesDir . "/receipt.txt"); + $pdfBytes = file_get_contents(\TestingUtilities::getFileTypesDir() . "/receipt.txt"); $inputDoc = new Base64Input($pdfBytes, "dummy.pdf"); $contents = $inputDoc->readContents(); $this->assertEquals("dummy.pdf", $contents[0]); @@ -227,41 +215,43 @@ public function testShouldNotRaiseMimeErrorForBrokenFixablePdf() { $this->expectNotToPerformAssertions(); - $this->dummyClient->sourceFromPath($this->fileTypesDir . '/pdf/broken_fixable.pdf', true); + $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . '/pdf/broken_fixable.pdf', true); } public function testShouldRaiseErrorForBrokenUnfixablePdf() { $this->expectException(MindeeSourceException::class); - $this->dummyClient->sourceFromPath($this->fileTypesDir . '/pdf/broken_unfixable.pdf', true); + $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . '/pdf/broken_unfixable.pdf', true); } public function testShouldSendCorrectResultsForBrokenFixableInvoicePdf() { - $sourceDocOriginal = $this->dummyClient->sourceFromPath($this->productsDir . '/invoices/invoice.pdf'); + $sourceDocOriginal = $this->dummyClient->sourceFromPath( + \TestingUtilities::getV1DataDir() . '/products/invoices/invoice.pdf' + ); - $sourceDocFixed = $this->dummyClient->sourceFromPath($this->fileTypesDir . '/pdf/broken_invoice.pdf', true); + $sourceDocFixed = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . '/pdf/broken_invoice.pdf', true); $this->assertEquals($sourceDocFixed->readContents()[1], $sourceDocOriginal->readContents()[1]); } public function testImageQualityCompressionFromInputSource() { - $receiptInput = $this->dummyClient->sourceFromPath($this->fileTypesDir . '/receipt.jpg'); + $receiptInput = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . '/receipt.jpg'); $receiptInput->compress(80); file_put_contents( - $this->outputDir . "/compress_indirect.jpg", + \TestingUtilities::getRootDataDir() . "/output/compress_indirect.jpg", file_get_contents($receiptInput->fileObject->getFilename()) ); - $sizeOriginal = filesize($this->fileTypesDir . '/receipt.jpg'); - $sizeCompressed = filesize($this->outputDir . "/compress_indirect.jpg"); + $sizeOriginal = filesize(\TestingUtilities::getFileTypesDir() . '/receipt.jpg'); + $sizeCompressed = filesize(\TestingUtilities::getRootDataDir() . "/output/compress_indirect.jpg"); $this->assertGreaterThan($sizeCompressed, $sizeOriginal); } public function testDirectImageQualityCompression() { - $receiptInput = $this->dummyClient->sourceFromPath($this->fileTypesDir . '/receipt.jpg'); - $sizeOriginal = filesize($this->fileTypesDir . '/receipt.jpg'); + $receiptInput = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . '/receipt.jpg'); + $sizeOriginal = filesize(\TestingUtilities::getFileTypesDir() . '/receipt.jpg'); $compresses = [ 100 => ImageCompressor::compress($receiptInput->fileObject, 100), 85 => ImageCompressor::compress($receiptInput->fileObject), @@ -271,11 +261,11 @@ public function testDirectImageQualityCompression() ]; $outputFiles = [ - 100 => $this->outputDir . "/compress100.jpg", - 85 => $this->outputDir . "/compress85.jpg", - 50 => $this->outputDir . "/compress50.jpg", - 10 => $this->outputDir . "/compress10.jpg", - 1 => $this->outputDir . "/compress1.jpg", + 100 => \TestingUtilities::getRootDataDir() . "/output/compress100.jpg", + 85 => \TestingUtilities::getRootDataDir() . "/output/compress85.jpg", + 50 => \TestingUtilities::getRootDataDir() . "/output/compress50.jpg", + 10 => \TestingUtilities::getRootDataDir() . "/output/compress10.jpg", + 1 => \TestingUtilities::getRootDataDir() . "/output/compress1.jpg", ]; $compressSize = []; @@ -295,9 +285,9 @@ public function testDirectImageQualityCompression() public function testPDFSourceText() { - $imageInput = $this->dummyClient->sourceFromPath($this->fileTypesDir . '/receipt.jpg'); - $pdfEmptyInput = $this->dummyClient->sourceFromPath($this->fileTypesDir . '/pdf/blank_1.pdf'); - $pdfSourceText = $this->dummyClient->sourceFromPath($this->fileTypesDir . '/pdf/multipage.pdf'); + $imageInput = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . '/receipt.jpg'); + $pdfEmptyInput = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); + $pdfSourceText = $this->dummyClient->sourceFromPath(\TestingUtilities::getFileTypesDir() . '/pdf/multipage.pdf'); $this->assertTrue($pdfSourceText->hasSourceText(), "Source text should be properly detected."); $this->assertFalse($pdfEmptyInput->hasSourceText(), "Empty PDFs should not have source text detected."); $this->assertFalse($imageInput->hasSourceText(), "An image should not have any text."); @@ -306,35 +296,33 @@ public function testPDFSourceText() public function testCompressPDFFromInputSource() { $pdfInput = $this->dummyClient->sourceFromPath( - $this->fileTypesDir . "pdf/not_blank_image_only.pdf" + \TestingUtilities::getFileTypesDir() . "/pdf/not_blank_image_only.pdf" ); $this->assertFalse($pdfInput->hasSourceText()); file_put_contents( - $this->outputDir . "/not_compressed.pdf", + \TestingUtilities::getRootDataDir() . "/output/not_compressed.pdf", file_get_contents($pdfInput->fileObject->getFilename()) ); - $sizeOriginal = filesize($this->fileTypesDir . '/pdf/not_blank_image_only.pdf'); - $sizeIgnored = filesize($this->outputDir . "/not_compressed.pdf"); + $sizeOriginal = filesize(\TestingUtilities::getFileTypesDir() . '/pdf/not_blank_image_only.pdf'); + $sizeIgnored = filesize(\TestingUtilities::getRootDataDir() . "/output/not_compressed.pdf"); $this->assertEquals($sizeIgnored, $sizeOriginal); $pdfInput->compress(90, null, null, true, false); file_put_contents( - $this->outputDir . "/compress_indirect.pdf", + \TestingUtilities::getRootDataDir() . "/output/compress_indirect.pdf", file_get_contents($pdfInput->fileObject->getFilename()) ); - $sizeCompressed = filesize($this->outputDir . '/compress_indirect.pdf'); + $sizeCompressed = filesize(\TestingUtilities::getRootDataDir() . '/output/compress_indirect.pdf'); $this->assertLessThan($sizeOriginal, $sizeCompressed); } public function testCompressPDFFromCompressor() { $pdfInput = $this->dummyClient->sourceFromPath( - $this->productsDir . - '/invoice_splitter/default_sample.pdf' + \TestingUtilities::getV1DataDir() . '/products/invoice_splitter/default_sample.pdf' ); - $sizeOriginal = filesize($this->productsDir . - '/invoice_splitter/default_sample.pdf'); + $sizeOriginal = filesize(\TestingUtilities::getV1DataDir() . '/products/invoice_splitter/default_sample.pdf'); $this->assertFalse($pdfInput->hasSourceText()); $pdfCompresses = [ @@ -344,10 +332,10 @@ public function testCompressPDFFromCompressor() 10 => PDFCompressor::compress($pdfInput->fileObject, 10), ]; $outputFiles = [ - 85 => $this->outputDir . "/compress_direct_85.pdf", - 75 => $this->outputDir . "/compress_direct_75.pdf", - 50 => $this->outputDir . "/compress_direct_50.pdf", - 10 => $this->outputDir . "/compress_direct_10.pdf", + 85 => \TestingUtilities::getRootDataDir() . "/output/compress_direct_85.pdf", + 75 => \TestingUtilities::getRootDataDir() . "/output/compress_direct_75.pdf", + 50 => \TestingUtilities::getRootDataDir() . "/output/compress_direct_50.pdf", + 10 => \TestingUtilities::getRootDataDir() . "/output/compress_direct_10.pdf", ]; $compressSize = []; @@ -368,25 +356,25 @@ public function testSourceTextPDFCompression() { $pdfInput = $this->dummyClient->sourceFromPath( - $this->fileTypesDir . "pdf/multipage.pdf" + \TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf" ); $this->assertTrue($pdfInput->hasSourceText()); $pdfInput->compress(5, null, null, true, false); file_put_contents( - $this->outputDir . "/text_multipage.pdf", + \TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf", file_get_contents($pdfInput->fileObject->getFilename()) ); - $sizeOriginal = filesize($this->fileTypesDir . "pdf/multipage.pdf"); - $sizeTextCompressed = filesize($this->outputDir . "/text_multipage.pdf"); + $sizeOriginal = filesize(\TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $sizeTextCompressed = filesize(\TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf"); $this->assertEquals($sizeTextCompressed, $sizeOriginal); // Note: Greater size when compressed is expected due to original not having any images, so the operation will // be aborted. $this->assertEquals( str_repeat('*', 650), - implode('', str_replace(" ", "", PDFUtils::extractPagesTextElements($this->outputDir . "/text_multipage.pdf"))) + implode('', str_replace(" ", "", PDFUtils::extractPagesTextElements(\TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf"))) ); } } diff --git a/tests/Input/LocalResponseTest.php b/tests/Input/LocalResponseTest.php index 76b094f2..b89a76da 100644 --- a/tests/Input/LocalResponseTest.php +++ b/tests/Input/LocalResponseTest.php @@ -13,7 +13,7 @@ class LocalResponseTest extends TestCase protected function setUp(): void { - $this->filePath = (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/async/get_completed_empty.json"; + $this->filePath = \TestingUtilities::getV1DataDir() . '/async/get_completed_empty.json'; $this->signature = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0"; $this->dummyKey = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; } diff --git a/tests/Input/URLInputSourceTest.php b/tests/Input/URLInputSourceTest.php index 6d42ab03..bb43f4ae 100644 --- a/tests/Input/URLInputSourceTest.php +++ b/tests/Input/URLInputSourceTest.php @@ -13,15 +13,11 @@ class URLInputSourceTest extends TestCase { private string $oldKey; protected Client $dummyClient; - protected string $fileTypesDir; protected function setUp(): void { $this->oldKey = getEnv(API_KEY_ENV_NAME); $this->dummyClient = new Client("dummy-key"); - $this->fileTypesDir = ( - getenv('GITHUB_WORKSPACE') ?: "." - ) . "/tests/resources/file_types/"; } protected function tearDown(): void diff --git a/tests/Product/BarcodeReader/BarcodeReaderV1TestRegression.php b/tests/Product/BarcodeReader/BarcodeReaderV1TestRegression.php deleted file mode 100644 index 2a625bfa..00000000 --- a/tests/Product/BarcodeReader/BarcodeReaderV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/barcode_reader/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(BarcodeReaderV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Cropper/CropperV1TestRegression.php b/tests/Product/Cropper/CropperV1TestRegression.php deleted file mode 100644 index a98cc560..00000000 --- a/tests/Product/Cropper/CropperV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/cropper/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(CropperV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/FinancialDocument/FinancialDocumentV1TestRegression.php b/tests/Product/FinancialDocument/FinancialDocumentV1TestRegression.php deleted file mode 100644 index d3c6cfc3..00000000 --- a/tests/Product/FinancialDocument/FinancialDocumentV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/financial_document/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(FinancialDocumentV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Fr/BankAccountDetails/BankAccountDetailsV1TestRegression.php b/tests/Product/Fr/BankAccountDetails/BankAccountDetailsV1TestRegression.php deleted file mode 100644 index 630a3052..00000000 --- a/tests/Product/Fr/BankAccountDetails/BankAccountDetailsV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/bank_account_details/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(BankAccountDetailsV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Fr/BankAccountDetails/BankAccountDetailsV2TestRegression.php b/tests/Product/Fr/BankAccountDetails/BankAccountDetailsV2TestRegression.php deleted file mode 100644 index 5dca1c2b..00000000 --- a/tests/Product/Fr/BankAccountDetails/BankAccountDetailsV2TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/bank_account_details/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(BankAccountDetailsV2::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Fr/CarteGrise/CarteGriseV1TestRegression.php b/tests/Product/Fr/CarteGrise/CarteGriseV1TestRegression.php deleted file mode 100644 index 0005697b..00000000 --- a/tests/Product/Fr/CarteGrise/CarteGriseV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/carte_grise/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(CarteGriseV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Fr/HealthCard/HealthCardV1TestRegression.php b/tests/Product/Fr/HealthCard/HealthCardV1TestRegression.php deleted file mode 100644 index 70efc461..00000000 --- a/tests/Product/Fr/HealthCard/HealthCardV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/french_healthcard/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(HealthCardV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Fr/IdCard/IdCardV1TestRegression.php b/tests/Product/Fr/IdCard/IdCardV1TestRegression.php deleted file mode 100644 index 7da6152b..00000000 --- a/tests/Product/Fr/IdCard/IdCardV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/idcard_fr/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(IdCardV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Fr/IdCard/IdCardV2TestRegression.php b/tests/Product/Fr/IdCard/IdCardV2TestRegression.php deleted file mode 100644 index a858e1a1..00000000 --- a/tests/Product/Fr/IdCard/IdCardV2TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/idcard_fr/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(IdCardV2::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Invoice/InvoiceV4TestRegression.php b/tests/Product/Invoice/InvoiceV4TestRegression.php deleted file mode 100644 index 2d269629..00000000 --- a/tests/Product/Invoice/InvoiceV4TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/invoices/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(InvoiceV4::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/InvoiceSplitter/InvoiceSplitterV1TestRegression.php b/tests/Product/InvoiceSplitter/InvoiceSplitterV1TestRegression.php deleted file mode 100644 index 059ed71a..00000000 --- a/tests/Product/InvoiceSplitter/InvoiceSplitterV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/invoice_splitter/default_sample.pdf" - ); - $response = $this->mindeeClient->enqueueAndParse(InvoiceSplitterV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/MultiReceiptsDetector/MultiReceiptsDetectorV1TestRegression.php b/tests/Product/MultiReceiptsDetector/MultiReceiptsDetectorV1TestRegression.php deleted file mode 100644 index c5c61050..00000000 --- a/tests/Product/MultiReceiptsDetector/MultiReceiptsDetectorV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/multi_receipts_detector/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(MultiReceiptsDetectorV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Passport/PassportV1TestRegression.php b/tests/Product/Passport/PassportV1TestRegression.php deleted file mode 100644 index ce2059af..00000000 --- a/tests/Product/Passport/PassportV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/passport/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(PassportV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/ProductSharedData.php b/tests/Product/ProductSharedData.php deleted file mode 100644 index 79deb089..00000000 --- a/tests/Product/ProductSharedData.php +++ /dev/null @@ -1,11 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/expense_receipts/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(ReceiptV5::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/Product/Us/BankCheck/BankCheckV1TestRegression.php b/tests/Product/Us/BankCheck/BankCheckV1TestRegression.php deleted file mode 100644 index 4f77a2e5..00000000 --- a/tests/Product/Us/BankCheck/BankCheckV1TestRegression.php +++ /dev/null @@ -1,34 +0,0 @@ -rstRef = file_get_contents($productDir . "default_sample.rst"); - $this->mindeeClient = new Client(); - } - - public function testRegression() - { - $inputSource = $this->mindeeClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/bank_check/default_sample.jpg" - ); - $response = $this->mindeeClient->parse(BankCheckV1::class, $inputSource); - $response->document->id = RegressionUtilities::getId($this->rstRef); - $response->document->inference->product->version = RegressionUtilities::getVersion($this->rstRef); - $this->assertEquals($this->rstRef, strval($response->document)); - } -} diff --git a/tests/TestingUtilities.php b/tests/TestingUtilities.php index f80559a6..3849eb39 100644 --- a/tests/TestingUtilities.php +++ b/tests/TestingUtilities.php @@ -5,6 +5,37 @@ */ class TestingUtilities { + /** + * @return string Return the root of the testing library. + */ + public static function getRootDataDir(): string + { + return (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources"; + } + + /** + * @return string Return the root of the v1 data directory. + */ + public static function getV1DataDir(): string + { + return TestingUtilities::getRootDataDir() . "/v1"; + } + + /** + * @return string Return the root of the v2 data directory. + */ + public static function getV2DataDir(): string + { + return TestingUtilities::getRootDataDir() . "/v2"; + } + + /** + * @return string Return the root of the file types directory. + */ + public static function getFileTypesDir(): string + { + return TestingUtilities::getRootDataDir() . "/file_types"; + } /** * Retrieves the version in a string of a prediction's RST. * diff --git a/tests/CLI/MindeeCLICommandTest.php b/tests/V1/CLI/MindeeCLICommandTest.php similarity index 88% rename from tests/CLI/MindeeCLICommandTest.php rename to tests/V1/CLI/MindeeCLICommandTest.php index 2f7cf18b..fd222f94 100644 --- a/tests/CLI/MindeeCLICommandTest.php +++ b/tests/V1/CLI/MindeeCLICommandTest.php @@ -1,10 +1,10 @@ filePath = (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/file_types/pdf/blank_1.pdf"; + $this->filePath = \TestingUtilities::getFileTypesDir() . "/pdf/blank_1.pdf"; $this->apiKey = getenv('MINDEE_API_KEY'); } diff --git a/tests/CLI/MindeeCLICommandTestFunctional.php b/tests/V1/CLI/MindeeCLICommandTestFunctional.php similarity index 85% rename from tests/CLI/MindeeCLICommandTestFunctional.php rename to tests/V1/CLI/MindeeCLICommandTestFunctional.php index a35316f8..65452622 100644 --- a/tests/CLI/MindeeCLICommandTestFunctional.php +++ b/tests/V1/CLI/MindeeCLICommandTestFunctional.php @@ -1,10 +1,10 @@ apiKey]; if ($initialArgs) { $args = array_merge($args, $initialArgs); diff --git a/tests/CLI/MindeeCLITestingUtilities.php b/tests/V1/CLI/MindeeCLITestingUtilities.php similarity index 97% rename from tests/CLI/MindeeCLITestingUtilities.php rename to tests/V1/CLI/MindeeCLITestingUtilities.php index bfe1e07b..b7ed9b13 100644 --- a/tests/CLI/MindeeCLITestingUtilities.php +++ b/tests/V1/CLI/MindeeCLITestingUtilities.php @@ -1,6 +1,6 @@ errorDir = (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/errors/"; + $this->errorDir = \TestingUtilities::getV1DataDir() . "/errors/"; $this->dummyClient = new Client("dummy-key"); $this->dummyFile = $this->dummyClient->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/file_types/pdf/blank.pdf" + \TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf" ); } diff --git a/tests/Extraction/ImageExtractorTest.php b/tests/V1/Extraction/ImageExtractorTest.php similarity index 63% rename from tests/Extraction/ImageExtractorTest.php rename to tests/V1/Extraction/ImageExtractorTest.php index 2084e18a..a0aa503f 100644 --- a/tests/Extraction/ImageExtractorTest.php +++ b/tests/V1/Extraction/ImageExtractorTest.php @@ -1,6 +1,6 @@ dummyClient = new Client("dummy-key"); - $this->outputDir = (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/output/"; } public function testGivenAnImageShouldExtractPositionFields() { - $image = new PathInput((getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/multi_receipts_detector/default_sample.jpg"); + $image = new PathInput( + \TestingUtilities::getV1DataDir() . "/products/multi_receipts_detector/default_sample.jpg" + ); $response = $this->getMultiReceiptsDetectorPrediction("complete"); $inference = $response->document->inference; @@ -34,7 +35,7 @@ public function testGivenAnImageShouldExtractPositionFields() $subImages = $extractor->extractImagesFromPage($page->prediction->receipts, $page->id); foreach ($subImages as $i => $extractedImage) { $this->assertNotNull($extractedImage->image); - $extractedImage->writeToFile($this->outputDir); + $extractedImage->writeToFile(\TestingUtilities::getRootDataDir() . "/output"); $source = $extractedImage->asInputSource(); $this->assertEquals( @@ -47,14 +48,14 @@ public function testGivenAnImageShouldExtractPositionFields() private function getMultiReceiptsDetectorPrediction($name) { - $fileName = (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/multi_receipts_detector/response_v1/{$name}.json"; + $fileName = \TestingUtilities::getV1DataDir() . "/products/multi_receipts_detector/response_v1/{$name}.json"; $localResponse = new LocalResponse($fileName); return $this->dummyClient->loadPrediction(MultiReceiptsDetectorV1::class, $localResponse); } public function testGivenAnImageShouldExtractValueFields() { - $image = new PathInput((getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/barcode_reader/default_sample.jpg"); + $image = new PathInput(\TestingUtilities::getV1DataDir() . "/products/barcode_reader/default_sample.jpg"); $response = $this->getBarcodeReaderPrediction("complete"); $inference = $response->document->inference; @@ -70,13 +71,13 @@ public function testGivenAnImageShouldExtractValueFields() sprintf("barcodes_1D_page-001_%03d.jpg", $i + 1), $source->fileName ); - $extractedImage->writeToFile($this->outputDir); + $extractedImage->writeToFile(\TestingUtilities::getRootDataDir() . "/output"); } $codes2D = $extractor->extractImagesFromPage($page->prediction->codes2D, $page->id, "barcodes_2D.jpg"); foreach ($codes2D as $extractedImage) { $this->assertNotNull($extractedImage->image); - $extractedImage->writeToFile($this->outputDir); + $extractedImage->writeToFile(\TestingUtilities::getRootDataDir() . "/output"); } } } @@ -84,7 +85,7 @@ public function testGivenAnImageShouldExtractValueFields() public function testGivenAPdfShouldExtractPositionFields() { $imageInput = new PathInput( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/multi_receipts_detector/multipage_sample.pdf" + \TestingUtilities::getV1DataDir() . "/products/multi_receipts_detector/multipage_sample.pdf" ); $response = $this->getMultiReceiptsDetectorPrediction("multipage_sample"); $inference = $response->document->inference; @@ -98,7 +99,7 @@ public function testGivenAPdfShouldExtractPositionFields() foreach ($subImages as $i => $extractedImage) { $this->assertNotNull($extractedImage->image); - $extractedImage->writeToFile($this->outputDir); + $extractedImage->writeToFile(\TestingUtilities::getRootDataDir() . "/output"); $source = $extractedImage->asInputSource(); $this->assertEquals( @@ -111,7 +112,7 @@ public function testGivenAPdfShouldExtractPositionFields() private function getBarcodeReaderPrediction($name) { - $fileName = (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/barcode_reader/response_v1/{$name}.json"; + $fileName = \TestingUtilities::getV1DataDir() . "/products/barcode_reader/response_v1/{$name}.json"; $localResponse = new LocalResponse($fileName); return $this->dummyClient->loadPrediction(BarcodeReaderV1::class, $localResponse); } @@ -119,20 +120,20 @@ private function getBarcodeReaderPrediction($name) protected function tearDown(): void { $filesToDelete = [ - $this->outputDir . "/barcodes_1D_page-001_001.jpg", - $this->outputDir . "/barcodes_2D_page-001_001.jpg", - $this->outputDir . "/barcodes_2D_page-001_002.jpg", - $this->outputDir . "/multipage_sample_page-001_001.jpg", - $this->outputDir . "/multipage_sample_page-001_002.jpg", - $this->outputDir . "/multipage_sample_page-001_003.jpg", - $this->outputDir . "/multipage_sample_page-002_001.jpg", - $this->outputDir . "/multipage_sample_page-002_002.jpg", - $this->outputDir . "/default_sample_page-001_001.jpg", - $this->outputDir . "/default_sample_page-001_002.jpg", - $this->outputDir . "/default_sample_page-001_003.jpg", - $this->outputDir . "/default_sample_page-001_004.jpg", - $this->outputDir . "/default_sample_page-001_005.jpg", - $this->outputDir . "/default_sample_page-001_006.jpg", + \TestingUtilities::getRootDataDir() . "/output/barcodes_1D_page-001_001.jpg", + \TestingUtilities::getRootDataDir() . "/output/barcodes_2D_page-001_001.jpg", + \TestingUtilities::getRootDataDir() . "/output/barcodes_2D_page-001_002.jpg", + \TestingUtilities::getRootDataDir() . "/output/multipage_sample_page-001_001.jpg", + \TestingUtilities::getRootDataDir() . "/output/multipage_sample_page-001_002.jpg", + \TestingUtilities::getRootDataDir() . "/output/multipage_sample_page-001_003.jpg", + \TestingUtilities::getRootDataDir() . "/output/multipage_sample_page-002_001.jpg", + \TestingUtilities::getRootDataDir() . "/output/multipage_sample_page-002_002.jpg", + \TestingUtilities::getRootDataDir() . "/output/default_sample_page-001_001.jpg", + \TestingUtilities::getRootDataDir() . "/output/default_sample_page-001_002.jpg", + \TestingUtilities::getRootDataDir() . "/output/default_sample_page-001_003.jpg", + \TestingUtilities::getRootDataDir() . "/output/default_sample_page-001_004.jpg", + \TestingUtilities::getRootDataDir() . "/output/default_sample_page-001_005.jpg", + \TestingUtilities::getRootDataDir() . "/output/default_sample_page-001_006.jpg", ]; foreach ($filesToDelete as $file) { @@ -141,5 +142,4 @@ protected function tearDown(): void } } } - } diff --git a/tests/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php b/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php similarity index 92% rename from tests/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php rename to tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php index 4a8decf9..d4fd9718 100644 --- a/tests/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php +++ b/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php @@ -1,5 +1,7 @@ enqueueAndParse(InvoiceSplitterV1::class, $invoiceSplitterInput); $inference = $response->document->inference; diff --git a/tests/Extraction/PdfExtractorTest.php b/tests/V1/Extraction/PdfExtractorTest.php similarity index 83% rename from tests/Extraction/PdfExtractorTest.php rename to tests/V1/Extraction/PdfExtractorTest.php index b4447ec1..caca0452 100644 --- a/tests/Extraction/PdfExtractorTest.php +++ b/tests/V1/Extraction/PdfExtractorTest.php @@ -1,10 +1,9 @@ assertFalse($localInput->isPdf()); $extractor = new PdfExtractor($localInput); @@ -34,7 +33,7 @@ public function testGivenAnImageShouldExtractAPDF() */ public function testGivenAPDFShouldExtractInvoicesNoStrict() { - $pdf = new PathInput((getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/invoice_splitter/invoice_5p.pdf"); + $pdf = new PathInput(\TestingUtilities::getV1DataDir() . "/products/invoice_splitter/invoice_5p.pdf"); $response = $this->getPrediction(); $this->assertNotNull($response); $inference = $response->document->inference; @@ -56,7 +55,7 @@ public function testGivenAPDFShouldExtractInvoicesNoStrict() */ public function testGivenAPDFShouldExtractInvoicesStrict() { - $pdf = new PathInput((getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/invoice_splitter/invoice_5p.pdf"); + $pdf = new PathInput(\TestingUtilities::getV1DataDir() . "/products/invoice_splitter/invoice_5p.pdf"); $response = $this->getPrediction(); $this->assertNotNull($response); $inference = $response->document->inference; @@ -74,7 +73,7 @@ public function testGivenAPDFShouldExtractInvoicesStrict() private function getPrediction() { - $fileName = (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/invoice_splitter/response_v1/complete.json"; + $fileName = \TestingUtilities::getV1DataDir() . "/products/invoice_splitter/response_v1/complete.json"; $localResponse = new LocalResponse($fileName); return $this->dummyClient->loadPrediction(InvoiceSplitterV1::class, $localResponse); } diff --git a/tests/Http/MindeeApiTest.php b/tests/V1/Http/MindeeApiTest.php similarity index 98% rename from tests/Http/MindeeApiTest.php rename to tests/V1/Http/MindeeApiTest.php index b27138b4..bc355a4f 100644 --- a/tests/Http/MindeeApiTest.php +++ b/tests/V1/Http/MindeeApiTest.php @@ -1,12 +1,11 @@ client = new Client(); - $this->outputFilePath = (getenv('GITHUB_WORKSPACE') ?: ".") . - "/tests/resources/output/"; - $this->referenceFilePath = "https://github.com/mindee/client-lib-test-data/blob/main/v1/products/invoice_splitter/invoice_5p.pdf?raw=true"; + $this->outputFilePath = \TestingUtilities::getRootDataDir() . "/output/"; + $this->referenceFilePath = getenv('MINDEE_V2_SE_TESTS_BLANK_PDF_URL'); } public static function tearDownAfterClass(): void { - unlink((getenv('GITHUB_WORKSPACE') ?: ".") . - "/tests/resources/output/invoice_5p.pdf"); - unlink((getenv('GITHUB_WORKSPACE') ?: ".") . - "/tests/resources/output/customFileName.pdf"); + unlink(\TestingUtilities::getRootDataDir() . "/output/invoice_5p.pdf"); + unlink(\TestingUtilities::getRootDataDir() . "/output/customFileName.pdf"); } public function testLoadLocalFile() diff --git a/tests/Parsing/Common/AsyncPredictResponseTest.php b/tests/V1/Parsing/Common/AsyncPredictResponseTest.php similarity index 97% rename from tests/Parsing/Common/AsyncPredictResponseTest.php rename to tests/V1/Parsing/Common/AsyncPredictResponseTest.php index 40bc7447..f48e153f 100644 --- a/tests/Parsing/Common/AsyncPredictResponseTest.php +++ b/tests/V1/Parsing/Common/AsyncPredictResponseTest.php @@ -1,6 +1,6 @@ filePathPostSuccess = $asyncDir . "/post_success.json"; $this->filePathPostFail = $asyncDir . "/post_fail_forbidden.json"; $this->filePathGetProcessing = $asyncDir . "/get_processing.json"; diff --git a/tests/Parsing/Common/Extras/CropperExtraTest.php b/tests/V1/Parsing/Common/Extras/CropperExtraTest.php similarity index 91% rename from tests/Parsing/Common/Extras/CropperExtraTest.php rename to tests/V1/Parsing/Common/Extras/CropperExtraTest.php index abacc0ff..62ce9757 100644 --- a/tests/Parsing/Common/Extras/CropperExtraTest.php +++ b/tests/V1/Parsing/Common/Extras/CropperExtraTest.php @@ -1,11 +1,9 @@ cropperDir = ( - getenv('GITHUB_WORKSPACE') ?: "." - ) . "/tests/resources/extras/cropper/"; + $this->cropperDir = \TestingUtilities::getV1DataDir() . "/extras/cropper/"; $completeDocFile = file_get_contents($this->cropperDir . "complete.json"); $completeDocJSON = json_decode($completeDocFile, true); $this->completeDoc = new Document(ReceiptV5::class, $completeDocJSON["document"]); diff --git a/tests/Parsing/Common/Extras/ExtrasIntegrationFunctional.php b/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php similarity index 86% rename from tests/Parsing/Common/Extras/ExtrasIntegrationFunctional.php rename to tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php index c75f4411..65e84521 100644 --- a/tests/Parsing/Common/Extras/ExtrasIntegrationFunctional.php +++ b/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php @@ -1,6 +1,6 @@ client->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/invoices/default_sample.jpg" + \TestingUtilities::getV1DataDir() . "/products/invoices/default_sample.jpg" ); $predictOptions = new PredictOptions(); $predictOptions->setCropper(true); @@ -37,7 +37,7 @@ public function testShouldSendCropperExtra(): void public function testShouldSendFullTextOcrExtra(): void { $sample = $this->client->sourceFromPath( - (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/international_id/default_sample.jpg" + \TestingUtilities::getV1DataDir() . "/products/international_id/default_sample.jpg" ); $predictOptions = new PredictOptions(); $predictOptions->setFullText(true); diff --git a/tests/Parsing/Common/Extras/FullTextOcrExtraTest.php b/tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php similarity index 93% rename from tests/Parsing/Common/Extras/FullTextOcrExtraTest.php rename to tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php index 3dd90b0e..48896e73 100644 --- a/tests/Parsing/Common/Extras/FullTextOcrExtraTest.php +++ b/tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php @@ -1,5 +1,7 @@ extrasDir = (getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/extras"; + $this->extrasDir = \TestingUtilities::getV1DataDir() . "/extras"; } private function loadDocument() diff --git a/tests/Parsing/Common/Ocr/OcrTest.php b/tests/V1/Parsing/Common/Ocr/OcrTest.php similarity index 84% rename from tests/Parsing/Common/Ocr/OcrTest.php rename to tests/V1/Parsing/Common/Ocr/OcrTest.php index bd9d9492..0fd958d3 100644 --- a/tests/Parsing/Common/Ocr/OcrTest.php +++ b/tests/V1/Parsing/Common/Ocr/OcrTest.php @@ -1,6 +1,6 @@ ocrObject = new Ocr($jsonData["document"]["ocr"]); @@ -20,9 +18,7 @@ protected function setup(): void{ public function testResponse() { $expectedText = file_get_contents( - ( - getenv('GITHUB_WORKSPACE') ?: "." - ) . "/tests/resources/extras/ocr/ocr.txt" + \TestingUtilities::getV1DataDir() . "/extras/ocr/ocr.txt" ); $this->assertEquals($expectedText, strval($this->ocrObject)); $this->assertEquals($expectedText, strval($this->ocrObject->mvisionV1->pages[0])); diff --git a/tests/Parsing/Common/PredictResponseTest.php b/tests/V1/Parsing/Common/PredictResponseTest.php similarity index 82% rename from tests/Parsing/Common/PredictResponseTest.php rename to tests/V1/Parsing/Common/PredictResponseTest.php index aa1a15f1..ebcd8359 100644 --- a/tests/Parsing/Common/PredictResponseTest.php +++ b/tests/V1/Parsing/Common/PredictResponseTest.php @@ -1,6 +1,6 @@ internationalIdV1CompleteDoc = new Document( GeneratedV1::class, json_decode( - file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/complete_international_id_v1.json"), + file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/complete_international_id_v1.json"), true )["document"] ); @@ -35,7 +34,7 @@ protected function setUp(): void $this->internationalIdV1EmptyDoc = new Document( GeneratedV1::class, json_decode( - file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/empty_international_id_v1.json"), + file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/empty_international_id_v1.json"), true )["document"] ); @@ -43,7 +42,7 @@ protected function setUp(): void $this->invoiceV4EmptyDoc = new Document( GeneratedV1::class, json_decode( - file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/empty_invoice_v4.json"), + file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/empty_invoice_v4.json"), true )["document"] ); @@ -51,13 +50,13 @@ protected function setUp(): void $this->invoiceV4CompleteDoc = new Document( GeneratedV1::class, json_decode( - file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/complete_invoice_v4.json"), + file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/complete_invoice_v4.json"), true )["document"] ); $jsonData = json_decode( - file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/complete_invoice_v4.json"), + file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/complete_invoice_v4.json"), true ); $this->invoiceV4Page0 = new Page( @@ -68,7 +67,7 @@ protected function setUp(): void public function testInternationalIdV1EmptyDoc(): void { - $docStr = file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/summary_empty_international_id_v1.rst"); + $docStr = file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/summary_empty_international_id_v1.rst"); $fields = $this->internationalIdV1EmptyDoc->inference->prediction->fields; @@ -123,7 +122,7 @@ public function testInternationalIdV1EmptyDoc(): void public function testInternationalIdV1CompleteDoc(): void { - $docStr = file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/summary_full_international_id_v1.rst"); + $docStr = file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/summary_full_international_id_v1.rst"); $fields = $this->internationalIdV1CompleteDoc->inference->prediction->fields; @@ -179,7 +178,7 @@ public function testInternationalIdV1CompleteDoc(): void public function testInvoiceV4CompleteDoc(): void { - $docStr = file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/summary_full_invoice_v4.rst"); + $docStr = file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/summary_full_invoice_v4.rst"); $fields = $this->invoiceV4CompleteDoc->inference->prediction->fields; @@ -257,7 +256,7 @@ public function testInvoiceV4CompleteDoc(): void public function testInvoiceV4Page0() { - $docStr = file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/summary_page0_invoice_v4.rst"); + $docStr = file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/summary_page0_invoice_v4.rst"); $this->assertInstanceOf(StringField::class, $this->invoiceV4Page0->prediction->fields["customer_address"]); $this->assertNull($this->invoiceV4Page0->prediction->fields["customer_address"]->value); @@ -328,7 +327,7 @@ public function testInvoiceV4Page0() public function testInvoiceV4EmptyDoc() { - $docStr = file_get_contents(PRODUCT_DATA_DIR . "/generated/response_v1/summary_empty_invoice_v4.rst"); + $docStr = file_get_contents(\TestingUtilities::getV1DataDir() . "/products/generated/response_v1/summary_empty_invoice_v4.rst"); $this->assertInstanceOf(StringField::class, $this->invoiceV4EmptyDoc->inference->prediction->fields["customer_address"]); $this->assertNull($this->invoiceV4EmptyDoc->inference->prediction->fields["customer_address"]->value); diff --git a/tests/Product/Ind/IndianPassport/IndianPassportV1Test.php b/tests/V1/Product/Ind/IndianPassport/IndianPassportV1Test.php similarity index 92% rename from tests/Product/Ind/IndianPassport/IndianPassportV1Test.php rename to tests/V1/Product/Ind/IndianPassport/IndianPassportV1Test.php index f0bd40d1..09e8735e 100644 --- a/tests/Product/Ind/IndianPassport/IndianPassportV1Test.php +++ b/tests/V1/Product/Ind/IndianPassport/IndianPassportV1Test.php @@ -1,10 +1,9 @@ findocSamplePath = ( - $rootPath . "/tests/resources/products/financial_document/default_sample.jpg" + TestingUtilities::getV1DataDir() . "/products/financial_document/default_sample.jpg" ); $this->workflowDir = ( - $rootPath . "/tests/resources/workflows/" + TestingUtilities::getV1DataDir() . "/workflows/" ); } diff --git a/tests/Workflow/WorkflowTestFunctional.php b/tests/V1/Workflow/WorkflowTestFunctional.php similarity index 91% rename from tests/Workflow/WorkflowTestFunctional.php rename to tests/V1/Workflow/WorkflowTestFunctional.php index beb85fee..1144e612 100644 --- a/tests/Workflow/WorkflowTestFunctional.php +++ b/tests/V1/Workflow/WorkflowTestFunctional.php @@ -1,6 +1,6 @@ mindeeClient = new Client(); $this->workflowId = getenv('WORKFLOW_ID') ?: ''; $this->predictionType = FinancialDocumentV1::class; $this->inputSource = $this->mindeeClient->sourceFromPath( - $rootPath . "/tests/resources/products/financial_document/default_sample.jpg" + \TestingUtilities::getV1DataDir() . "/products/financial_document/default_sample.jpg" ); } diff --git a/tests/Parsing/V2/InferenceTest.php b/tests/V2/InferenceTest.php similarity index 97% rename from tests/Parsing/V2/InferenceTest.php rename to tests/V2/InferenceTest.php index acfecc54..ce1ad465 100644 --- a/tests/Parsing/V2/InferenceTest.php +++ b/tests/V2/InferenceTest.php @@ -1,5 +1,7 @@ assertFileExists($fullPath, "Resource file must exist: $resourcePath"); $localResponse = new LocalResponse($fullPath); @@ -25,7 +30,7 @@ private function loadFromResource(string $resourcePath): InferenceResponse private function readFileAsString(string $path): string { - $fullPath = __DIR__ . '/../../resources/' . $path; + $fullPath = TestingUtilities::getRootDataDir() . $path; $this->assertFileExists($fullPath, "Resource file must exist: $path"); return file_get_contents($fullPath); @@ -296,8 +301,8 @@ public function testRawTextsMustBeAccessible(): void */ public function testRstDisplayMustBeAccessible(): void { - $response = $this->loadFromResource('v2/inference/standard_field_types.json'); - $expectedRst = $this->readFileAsString('v2/inference/standard_field_types.rst'); + $response = $this->loadFromResource('/v2/inference/standard_field_types.json'); + $expectedRst = $this->readFileAsString('/v2/inference/standard_field_types.rst'); $inference = $response->inference; $this->assertNotNull($inference); $this->assertEquals($expectedRst, strval($response->inference)); diff --git a/tests/resources b/tests/resources index bc8356c1..b0d725b7 160000 --- a/tests/resources +++ b/tests/resources @@ -1 +1 @@ -Subproject commit bc8356c1ce52d60351ed3430d336f33366025012 +Subproject commit b0d725b71784a45db611c325739320b6c192b7e5 From 14162baa0f5b687e8bbb66a98726f5eeb2445d0a Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Thu, 13 Nov 2025 14:09:36 +0100 Subject: [PATCH 2/4] add missing import --- tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php b/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php index 583698a3..a82ba53c 100644 --- a/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php +++ b/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php @@ -1,5 +1,7 @@ Date: Thu, 13 Nov 2025 14:36:12 +0100 Subject: [PATCH 3/4] fix file names --- tests/V1/Input/URLInputSourceTestFunctional.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/V1/Input/URLInputSourceTestFunctional.php b/tests/V1/Input/URLInputSourceTestFunctional.php index 6ab5788b..432de859 100644 --- a/tests/V1/Input/URLInputSourceTestFunctional.php +++ b/tests/V1/Input/URLInputSourceTestFunctional.php @@ -21,7 +21,7 @@ protected function setUp(): void public static function tearDownAfterClass(): void { - unlink(\TestingUtilities::getRootDataDir() . "/output/invoice_5p.pdf"); + unlink(\TestingUtilities::getRootDataDir() . "/output/blank_1.pdf"); unlink(\TestingUtilities::getRootDataDir() . "/output/customFileName.pdf"); } @@ -30,8 +30,8 @@ public function testLoadLocalFile() $urlSource = $this->client->sourceFromUrl($this->referenceFilePath); $localSource = $urlSource->asLocalInputSource(); $result = $this->client->parse(InvoiceV4::class, $localSource); - $this->assertEquals(5, $result->document->nPages); - $this->assertEquals("invoice_5p.pdf", $result->document->filename); + $this->assertEquals(1, $result->document->nPages); + $this->assertEquals("blank_1.pdf", $result->document->filename); } public function testCustomFileName() @@ -39,7 +39,7 @@ public function testCustomFileName() $urlSource = $this->client->sourceFromUrl($this->referenceFilePath); $localSource = $urlSource->asLocalInputSource("customName.pdf"); $result = $this->client->parse(InvoiceV4::class, $localSource); - $this->assertEquals(5, $result->document->nPages); + $this->assertEquals(1, $result->document->nPages); $this->assertEquals("customName.pdf", $result->document->filename); } @@ -47,7 +47,7 @@ public function testSaveFile() { $urlSource = $this->client->sourceFromUrl($this->referenceFilePath); $urlSource->saveToFile($this->outputFilePath); - $this->assertFileExists($this->outputFilePath . "invoice_5p.pdf"); + $this->assertFileExists($this->outputFilePath . "blank_1.pdf"); } public function testSaveFileWithFilename() From 01323b9c62bca6f32c2b42c8f2acf2497c8bd417 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Thu, 13 Nov 2025 14:47:44 +0100 Subject: [PATCH 4/4] fix more mistakes --- tests/ClientV2TestFunctional.php | 4 +++- tests/V1/CLI/MindeeCLICommandTestFunctional.php | 1 + .../InvoiceSplitterAutoExtractionTestFunctional.php | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/ClientV2TestFunctional.php b/tests/ClientV2TestFunctional.php index 9eb2a0de..e5cc8a91 100644 --- a/tests/ClientV2TestFunctional.php +++ b/tests/ClientV2TestFunctional.php @@ -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); diff --git a/tests/V1/CLI/MindeeCLICommandTestFunctional.php b/tests/V1/CLI/MindeeCLICommandTestFunctional.php index 65452622..285a8dd6 100644 --- a/tests/V1/CLI/MindeeCLICommandTestFunctional.php +++ b/tests/V1/CLI/MindeeCLICommandTestFunctional.php @@ -5,6 +5,7 @@ require_once(__DIR__ . "/../../../vendor/autoload.php"); require_once(__DIR__ . "/../../../bin/MindeeCLIDocuments.php"); require_once(__DIR__ . "/../../TestingUtilities.php"); +require_once(__DIR__ . "/MindeeCLITestingUtilities.php"); use Mindee\CLI\MindeeCLIDocuments; use PHPUnit\Framework\TestCase; diff --git a/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php b/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php index d4fd9718..064752dd 100644 --- a/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php +++ b/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php @@ -33,8 +33,9 @@ private function prepareInvoiceReturn(string $rstFilePath, Document $invoicePred public function testPdfShouldExtractInvoicesStrict() { $client = new Client(); - $rootDir = \TestingUtilities::getV1DataDir() . self::PRODUCT_DATA_DIR; - $invoiceSplitterInput = new PathInput(filePath: $rootDir . '/invoice_splitter/default_sample.pdf'); + $invoiceSplitterInput = new PathInput( + filePath: TestingUtilities::getV1DataDir() . '/products/invoice_splitter/default_sample.pdf' + ); $response = $client->enqueueAndParse(InvoiceSplitterV1::class, $invoiceSplitterInput); $inference = $response->document->inference; $pdfExtractor = new PdfExtractor($invoiceSplitterInput); @@ -49,7 +50,7 @@ public function testPdfShouldExtractInvoicesStrict() $invoice0 = $client->parse(InvoiceV4::class, $extractedPdfsStrict[0]->asInputSource()); $testStringRstInvoice0 = $this->prepareInvoiceReturn( - rstFilePath: $rootDir . '/invoices/response_v4/summary_full_invoice_p1.rst', + rstFilePath: TestingUtilities::getV1DataDir() . '/products/invoices/response_v4/summary_full_invoice_p1.rst', invoicePrediction: $invoice0->document );