diff --git a/src/Input/LocalInputSource.php b/src/Input/LocalInputSource.php index 9abe4997..b77dd259 100644 --- a/src/Input/LocalInputSource.php +++ b/src/Input/LocalInputSource.php @@ -71,6 +71,26 @@ abstract class LocalInputSource extends InputSource */ public ?int $pageCount = null; + /** + * Base constructor, mostly used for Mime type checking. + */ + public function __construct() + { + $this->checkMimeType(); + try { + DependencyChecker::isGhostscriptAvailable(); + if ($this->isPdf()) { + $this->pageCount = $this->getPageCount(); + } else { + $this->pageCount = 1; + } + } catch (MindeeUnhandledException) { + error_log("PDF-handling features not available, page count set to null."); + } catch (Throwable $e) { + error_log("Could not open PDF due to exception '" . $e->getMessage() . "', setting page count to null."); + } + } + /** * Checks if the file needs fixing. */ @@ -103,26 +123,6 @@ private function checkMimeType(): void } } - /** - * Base constructor, mostly used for Mime type checking. - */ - public function __construct() - { - $this->checkMimeType(); - try { - DependencyChecker::isGhostscriptAvailable(); - if ($this->isPdf()) { - $this->pageCount = $this->getPageCount(); - } else { - $this->pageCount = 1; - } - } catch (MindeeUnhandledException) { - error_log("PDF-handling features not available, page count set to null."); - } catch (Throwable $e) { - error_log("Could not open PDF due to exception" . $e->getMessage() . ", setting page count to null."); - } - } - /** * Checks whether the file type is a PDF. * @@ -154,7 +154,7 @@ protected function getPageCount(): int return $pdf->setSourceFile($this->fileObject->getFilename()); } catch (PdfParserException $e) { throw new MindeePdfException( - "Failed to read PDF file.", + $e->getMessage(), ErrorCode::PDF_CANT_PROCESS, $e ); @@ -190,7 +190,7 @@ public function mergePdfPages(array $pageNumbers): void $pdf->Close(); } catch (PdfParserException|PdfReaderException $e) { throw new MindeePdfException( - "Failed to read PDF file.", + $e->getMessage(), ErrorCode::PDF_CANT_PROCESS, $e ); @@ -223,7 +223,7 @@ public function isPdfEmpty(int $threshold = 1024): bool } } catch (PdfParserException|PdfReaderException $e) { throw new MindeePdfException( - "Failed to read PDF file.", + $e->getMessage(), ErrorCode::PDF_CANT_PROCESS, $e ); diff --git a/tests/Input/LocalInputSourceTest.php b/tests/Input/LocalInputSourceTest.php index 885ac541..b6bb0b21 100644 --- a/tests/Input/LocalInputSourceTest.php +++ b/tests/Input/LocalInputSourceTest.php @@ -68,30 +68,29 @@ protected function tearDown(): void } } - public function testPdfCountPages(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - self::assertSame(12, $inputObj->pageCount); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + self::assertSame(12, $inputSource->pageCount); } public function testPdfPageCountNullOnUnsupportedCompression(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/XfaForm.pdf"); - self::assertNull($inputObj->pageCount); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/XfaForm.pdf"); + self::assertNull($inputSource->pageCount); } public function testPdfReconstructOK(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], KEEP_ONLY, 2)); - self::assertSame(5, $inputObj->pageCount); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], KEEP_ONLY, 2)); + self::assertSame(5, $inputSource->pageCount); } public function testPdfReadContents(): void { - $inputDoc = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $contents = $inputDoc->readContents(); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $contents = $inputSource->readContents(); self::assertSame("multipage.pdf", $contents[0]); } @@ -100,25 +99,25 @@ public function testPdfReadContents(): void */ public function testPdfCutNPages(array $indexes): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $inputObj->applyPageOptions(new PageOptions($indexes, KEEP_ONLY, 2)); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource->applyPageOptions(new PageOptions($indexes, KEEP_ONLY, 2)); try { $basePdf = new Fpdi(); $cutPdf = new Fpdi(); $pageCountCutPdf = $cutPdf->setSourceFile( TestingUtilities::getFileTypesDir() . "/pdf/multipage_cut-" . count($indexes) . ".pdf" ); - $pageCountBasePdf = $basePdf->setSourceFile($inputObj->fileObject->getFilename()); + $pageCountBasePdf = $basePdf->setSourceFile($inputSource->fileObject->getFilename()); $basePdf->Close(); $cutPdf->Close(); - self::assertSame(count($indexes), $inputObj->pageCount); + self::assertSame(count($indexes), $inputSource->pageCount); self::assertSame($pageCountCutPdf, $pageCountBasePdf); $basePdf = new Fpdi(); $cutPdf = new Fpdi(); for ($pageNumber = 0; $pageNumber < $pageCountBasePdf; $pageNumber++) { $cutPdf->setSourceFile(TestingUtilities::getFileTypesDir() . "/pdf/multipage_cut-" . count($indexes) . ".pdf"); - $basePdf->setSourceFile($inputObj->fileObject->getFilename()); + $basePdf->setSourceFile($inputSource->fileObject->getFilename()); $cutPdf->AddPage(); $cutPdf->useTemplate($cutPdf->importPage($pageNumber + 1)); $basePdf->AddPage(); @@ -142,61 +141,61 @@ public static function providePdfCutNPagesCases(): iterable public function testPdfKeep5FirstPages(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], KEEP_ONLY, 2)); - self::assertSame(5, $inputObj->pageCount); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], KEEP_ONLY, 2)); + self::assertSame(5, $inputSource->pageCount); } public function testPdfKeepInvalidPages(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $inputObj->applyPageOptions(new PageOptions([0, 1, 17], KEEP_ONLY, 2)); - self::assertSame(2, $inputObj->pageCount); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource->applyPageOptions(new PageOptions([0, 1, 17], KEEP_ONLY, 2)); + self::assertSame(2, $inputSource->pageCount); } public function testPdfRemove5LastPages(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $inputObj->applyPageOptions(new PageOptions([-5, -4, -3, -2, -1], REMOVE, 2)); - self::assertSame(7, $inputObj->pageCount); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource->applyPageOptions(new PageOptions([-5, -4, -3, -2, -1], REMOVE, 2)); + self::assertSame(7, $inputSource->pageCount); } public function testPdfRemove5FirstPages(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $inputObj->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], REMOVE, 2)); - self::assertSame(7, $inputObj->pageCount); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource->applyPageOptions(new PageOptions([0, 1, 2, 3, 4], REMOVE, 2)); + self::assertSame(7, $inputSource->pageCount); } public function testPdfRemoveInvalidPages(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $inputObj->applyPageOptions(new PageOptions([16], REMOVE, 2)); - self::assertSame(12, $inputObj->pageCount); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource->applyPageOptions(new PageOptions([16], REMOVE, 2)); + self::assertSame(12, $inputSource->pageCount); } public function testPdfKeepNoPages(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $this->expectException(MindeePdfException::class); - $inputObj->applyPageOptions(new PageOptions([], KEEP_ONLY, 2)); + $inputSource->applyPageOptions(new PageOptions([], KEEP_ONLY, 2)); } public function testPdfRemoveAllPages(): void { - $inputObj = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $this->expectException(MindeePdfException::class); - $pageOptions = new PageOptions(range(0, $inputObj->pageCount - 1), REMOVE, 2); - $inputObj->applyPageOptions(pageOptions: $pageOptions); + $pageOptions = new PageOptions(range(0, $inputSource->pageCount - 1), REMOVE, 2); + $inputSource->applyPageOptions(pageOptions: $pageOptions); } public function testPdfInputFromFile(): void { $fileContents = file_get_contents(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $fileRef = fopen(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf", "r"); - $inputDoc = new FileInput($fileRef); - $contents = $inputDoc->readContents(); + $inputSource = new FileInput($fileRef); + $contents = $inputSource->readContents(); self::assertSame("multipage.pdf", $contents[0]); self::assertSame($fileContents, $contents[1]); } @@ -204,17 +203,17 @@ public function testPdfInputFromFile(): void public function testPdfInputFromBytes(): void { $pdfBytes = file_get_contents(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); - $inputDoc = new BytesInput($pdfBytes, "dummy.pdf"); - $contents = $inputDoc->readContents(); + $inputSource = new BytesInput($pdfBytes, "dummy.pdf"); + $contents = $inputSource->readContents(); self::assertSame("dummy.pdf", $contents[0]); self::assertSame($pdfBytes, $contents[1]); } - public function testInputFromRawb64String(): void + public function testInputFromRawBase64String(): void { $pdfBytes = file_get_contents(TestingUtilities::getFileTypesDir() . "/receipt.txt"); - $inputDoc = new Base64Input($pdfBytes, "dummy.pdf"); - $contents = $inputDoc->readContents(); + $inputSource = new Base64Input($pdfBytes, "dummy.pdf"); + $contents = $inputSource->readContents(); self::assertSame("dummy.pdf", $contents[0]); self::assertSame(str_replace("\n", "", $pdfBytes), str_replace("\n", "", base64_encode($contents[1]))); } @@ -223,16 +222,16 @@ public function testShouldNotRaiseMimeErrorForBrokenFixablePdf(): void { $this->expectNotToPerformAssertions(); - $pathInput = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_fixable.pdf'); - $pathInput->fixPdf(); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_fixable.pdf'); + $inputSource->fixPdf(); } public function testShouldRaiseErrorForBrokenUnfixablePdf(): void { $this->expectException(MindeeSourceException::class); - $pathInput = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_unfixable.pdf'); - $pathInput->fixPdf(); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_unfixable.pdf'); + $inputSource->fixPdf(); } public function testShouldSendCorrectResultsForBrokenFixableInvoicePdf(): void @@ -248,11 +247,11 @@ public function testShouldSendCorrectResultsForBrokenFixableInvoicePdf(): void public function testImageQualityCompressionFromInputSource(): void { - $receiptInput = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); - $receiptInput->compress(80); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); + $inputSource->compress(80); file_put_contents( TestingUtilities::getRootDataDir() . "/output/compress_indirect.jpg", - file_get_contents($receiptInput->fileObject->getFilename()) + file_get_contents($inputSource->fileObject->getFilename()) ); $sizeOriginal = filesize(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); $sizeCompressed = filesize(TestingUtilities::getRootDataDir() . "/output/compress_indirect.jpg"); @@ -261,14 +260,14 @@ public function testImageQualityCompressionFromInputSource(): void public function testDirectImageQualityCompression(): void { - $receiptInput = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); $sizeOriginal = filesize(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); $compresses = [ - 100 => ImageCompressor::compress($receiptInput->fileObject, 100), - 85 => ImageCompressor::compress($receiptInput->fileObject), - 50 => ImageCompressor::compress($receiptInput->fileObject, 50), - 10 => ImageCompressor::compress($receiptInput->fileObject, 10), - 1 => ImageCompressor::compress($receiptInput->fileObject, 1), + 100 => ImageCompressor::compress($inputSource->fileObject, 100), + 85 => ImageCompressor::compress($inputSource->fileObject), + 50 => ImageCompressor::compress($inputSource->fileObject, 50), + 10 => ImageCompressor::compress($inputSource->fileObject, 10), + 1 => ImageCompressor::compress($inputSource->fileObject, 1), ]; $outputFiles = [ @@ -296,33 +295,33 @@ public function testDirectImageQualityCompression(): void public function testPdfSourceText(): void { - $imageInput = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg'); $pdfEmptyInput = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); $pdfSourceText = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage.pdf'); self::assertTrue($pdfSourceText->hasSourceText(), "Source text should be properly detected."); self::assertFalse($pdfEmptyInput->hasSourceText(), "Empty PDFs should not have source text detected."); - self::assertFalse($imageInput->hasSourceText(), "An image should not have any text."); + self::assertFalse($inputSource->hasSourceText(), "An image should not have any text."); } public function testCompressPdfFromInputSource(): void { - $pdfInput = new PathInput( + $inputSource = new PathInput( TestingUtilities::getFileTypesDir() . "/pdf/not_blank_image_only.pdf" ); - self::assertFalse($pdfInput->hasSourceText()); + self::assertFalse($inputSource->hasSourceText()); file_put_contents( TestingUtilities::getRootDataDir() . "/output/not_compressed.pdf", - file_get_contents($pdfInput->fileObject->getFilename()) + file_get_contents($inputSource->fileObject->getFilename()) ); $sizeOriginal = filesize(TestingUtilities::getFileTypesDir() . '/pdf/not_blank_image_only.pdf'); $sizeIgnored = filesize(TestingUtilities::getRootDataDir() . "/output/not_compressed.pdf"); self::assertSame($sizeIgnored, $sizeOriginal); - $pdfInput->compress(90, null, null, true, false); + $inputSource->compress(90, null, null, true, false); file_put_contents( TestingUtilities::getRootDataDir() . "/output/compress_indirect.pdf", - file_get_contents($pdfInput->fileObject->getFilename()) + file_get_contents($inputSource->fileObject->getFilename()) ); $sizeCompressed = filesize(TestingUtilities::getRootDataDir() . '/output/compress_indirect.pdf'); self::assertLessThan($sizeOriginal, $sizeCompressed); @@ -330,17 +329,17 @@ public function testCompressPdfFromInputSource(): void public function testCompressPdfFromCompressor(): void { - $pdfInput = new PathInput( + $inputSource = new PathInput( TestingUtilities::getV1DataDir() . '/products/invoice_splitter/default_sample.pdf' ); $sizeOriginal = filesize(TestingUtilities::getV1DataDir() . '/products/invoice_splitter/default_sample.pdf'); - self::assertFalse($pdfInput->hasSourceText()); + self::assertFalse($inputSource->hasSourceText()); $pdfCompresses = [ - 85 => PdfCompressor::compress($pdfInput->fileObject), - 75 => PdfCompressor::compress($pdfInput->fileObject, 75), - 50 => PdfCompressor::compress($pdfInput->fileObject, 50), - 10 => PdfCompressor::compress($pdfInput->fileObject, 10), + 85 => PdfCompressor::compress($inputSource->fileObject), + 75 => PdfCompressor::compress($inputSource->fileObject, 75), + 50 => PdfCompressor::compress($inputSource->fileObject, 50), + 10 => PdfCompressor::compress($inputSource->fileObject, 10), ]; $outputFiles = [ 85 => TestingUtilities::getRootDataDir() . "/output/compress_direct_85.pdf", @@ -366,16 +365,16 @@ public function testCompressPdfFromCompressor(): void public function testSourceTextPdfCompression(): void { - $pdfInput = new PathInput( + $inputSource = new PathInput( TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf" ); - self::assertTrue($pdfInput->hasSourceText()); + self::assertTrue($inputSource->hasSourceText()); - $pdfInput->compress(5, null, null, true, false); + $inputSource->compress(5, null, null, true, false); file_put_contents( TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf", - file_get_contents($pdfInput->fileObject->getFilename()) + file_get_contents($inputSource->fileObject->getFilename()) ); $sizeOriginal = filesize(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $sizeTextCompressed = filesize(TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf"); diff --git a/tests/Input/UrlInputSourceTest.php b/tests/Input/UrlInputSourceTest.php index b72c3827..59a8b7d0 100644 --- a/tests/Input/UrlInputSourceTest.php +++ b/tests/Input/UrlInputSourceTest.php @@ -29,8 +29,8 @@ protected function tearDown(): void public function testInputFromHttpsShouldNotThrow(): void { - $inputDoc = new UrlInputSource("https://example.com/invoice.pdf"); - self::assertInstanceOf(UrlInputSource::class, $inputDoc); + $inputSource = new UrlInputSource("https://example.com/invoice.pdf"); + self::assertInstanceOf(UrlInputSource::class, $inputSource); } public function testInputFromHttpShouldThrow(): void @@ -42,17 +42,17 @@ public function testInputFromHttpShouldThrow(): void public function testDownloadFileFails(): void { $dummyAddress = "addressthatdoesntworkforcipurposes"; - $urlSource = new UrlInputSource("https://$dummyAddress"); + $inputSource = new UrlInputSource("https://$dummyAddress"); $this->expectException(MindeeSourceException::class); $this->expectExceptionMessage("Failed to download file: Could not resolve host: $dummyAddress"); - $urlSource->asLocalInputSource("test.pdf"); + $inputSource->asLocalInputSource("test.pdf"); } public function testInvalidFileName(): void { - $urlSource = new UrlInputSource("https://addressthatdoesntworkforcipurposes"); + $inputSource = new UrlInputSource("https://addressthatdoesntworkforcipurposes"); $this->expectException(MindeeSourceException::class); $this->expectExceptionMessage("Filename must end with an extension."); - $urlSource->asLocalInputSource("toto"); + $inputSource->asLocalInputSource("toto"); } } diff --git a/tests/V2/ClientV2Test.php b/tests/V2/ClientV2Test.php index 5ffe9b15..9b94e284 100644 --- a/tests/V2/ClientV2Test.php +++ b/tests/V2/ClientV2Test.php @@ -149,9 +149,9 @@ public function testInvalidBaseUrlRaisesMindeeException(): void try { $client = new Client('dummy-key'); - $input = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); $params = new ExtractionParameters('dummy-model-id'); - $client->enqueueAndGetResult(ExtractionResponse::class, $input, $params); + $client->enqueueAndGetResult(ExtractionResponse::class, $inputSource, $params); } finally { if (null === $original) { putenv('MINDEE_V2_BASE_URL'); diff --git a/tests/V2/ClientV2TestFunctional.php b/tests/V2/ClientV2TestFunctional.php index b3fee34a..6fac1b64 100644 --- a/tests/V2/ClientV2TestFunctional.php +++ b/tests/V2/ClientV2TestFunctional.php @@ -29,13 +29,13 @@ protected function setUp(): void public function testParseFileEmptyMultiPageMustSucceed(): void { - $source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/object_streams.pdf'); $modelParams = new ExtractionParameters($this->modelId, rag: false, rawText: true); $pollingOptions = new PollingOptions(maxRetries: 100); $response = $this->mindeeClient->enqueueAndGetResult( ExtractionResponse::class, - $source, + $inputSource, $modelParams, $pollingOptions ); @@ -45,7 +45,7 @@ public function testParseFileEmptyMultiPageMustSucceed(): void $file = $inference->file; self::assertNotNull($file); - self::assertSame('multipage_cut-2.pdf', $file->name); + self::assertSame('object_streams.pdf', $file->name); self::assertSame(2, $file->pageCount); self::assertNotNull($inference->model); @@ -70,13 +70,13 @@ public function testParseFileEmptyMultiPageMustSucceed(): void */ public function testParseFileFilledSinglePageMustSucceed(): void { - $source = new PathInput( + $inputSource = new PathInput( TestingUtilities::getV1DataDir() . '/products/financial_document/default_sample.jpg' ); $modelParams = new ExtractionParameters($this->modelId, rag: false, textContext: 'this is an invoice'); - $response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $modelParams); + $response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $inputSource, $modelParams); self::assertNotNull($response); $inference = $response->inference; self::assertNotNull($inference); @@ -104,13 +104,12 @@ public function testParseFileFilledSinglePageMustSucceed(): void public function testInvalidUUIDMustThrowError(): void { - - $source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); $modelParams = new ExtractionParameters('INVALID MODEL ID'); try { - $this->mindeeClient->enqueue($source, $modelParams); + $this->mindeeClient->enqueue($inputSource, $modelParams); } catch (MindeeV2HttpException $e) { self::assertStringStartsWith('422-', $e->errorCode); self::assertNotEmpty($e->title); @@ -120,12 +119,12 @@ public function testInvalidUUIDMustThrowError(): void public function testUnknownModelMustThrowError(): void { - $source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); $modelParams = new ExtractionParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21', textContext: 'this is invalid'); try { - $this->mindeeClient->enqueue($source, $modelParams); + $this->mindeeClient->enqueue($inputSource, $modelParams); } catch (MindeeV2HttpException $e) { self::assertStringStartsWith('404-', $e->errorCode); self::assertNotEmpty($e->title); @@ -133,7 +132,6 @@ public function testUnknownModelMustThrowError(): void } } - public function testInvalidJobMustThrowError(): void { try { @@ -147,7 +145,7 @@ public function testInvalidJobMustThrowError(): void public function testInvalidWebhookIDsMustThrowError(): void { - $source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); + $inputSource = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); $modelParams = new ExtractionParameters( $this->modelId, @@ -161,7 +159,7 @@ public function testInvalidWebhookIDsMustThrowError(): void ); try { - $this->mindeeClient->enqueue($source, $modelParams); + $this->mindeeClient->enqueue($inputSource, $modelParams); } catch (MindeeV2HttpException $e) { self::assertStringStartsWith('422-', $e->errorCode); self::assertNotEmpty($e->title); @@ -190,7 +188,7 @@ public function testUrlInputSourceMustNotRaiseErrors(): void public function testDataSchemaMustSucceed(): void { - $source = new PathInput( + $inputSource = new PathInput( TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf' ); $dataSchemaReplace = file_get_contents( @@ -199,7 +197,7 @@ public function testDataSchemaMustSucceed(): void $modelParams = new ExtractionParameters($this->modelId, dataSchema: $dataSchemaReplace); - $response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $modelParams); + $response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $inputSource, $modelParams); self::assertNotNull($response); $inference = $response->inference; self::assertNotNull($inference); @@ -228,7 +226,7 @@ public function testDataSchemaMustSucceed(): void public function testMultipleWebhooksMustSucceed(): void { - $source = new PathInput( + $inputSource = new PathInput( TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf' ); @@ -238,7 +236,7 @@ public function testMultipleWebhooksMustSucceed(): void getenv('MINDEE_V2_FAILURE_WEBHOOK_ID'), getenv('MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID')] ); - $response = $this->mindeeClient->enqueue($source, $modelParams); + $response = $this->mindeeClient->enqueue($inputSource, $modelParams); self::assertCount(2, $response->job->webhooks); } } diff --git a/tests/resources b/tests/resources index 4b7f3376..5037ffc3 160000 --- a/tests/resources +++ b/tests/resources @@ -1 +1 @@ -Subproject commit 4b7f33766fab0e67804b84447b73c80a902d886a +Subproject commit 5037ffc3c443ec0c93ed673acd22d6ae1c65771a