11<?php
22
3- namespace V2 ;
3+ namespace V2 \ parsing ;
44
5+ use Mindee \Error \ErrorItem ;
56use Mindee \Geometry \Point ;
67use Mindee \Input \LocalResponse ;
8+ use Mindee \Parsing \V2 \ErrorResponse ;
79use Mindee \Parsing \V2 \Field \FieldConfidence ;
810use Mindee \Parsing \V2 \Field \ListField ;
911use Mindee \Parsing \V2 \Field \ObjectField ;
1012use Mindee \Parsing \V2 \Field \SimpleField ;
1113use Mindee \Parsing \V2 \InferenceResponse ;
14+ use Mindee \Parsing \V2 \JobResponse ;
1215use PHPUnit \Framework \TestCase ;
1316use TestingUtilities ;
1417
15- require_once (__DIR__ . "/../TestingUtilities.php " );
18+ require_once (__DIR__ . "/../../ TestingUtilities.php " );
1619
1720/**
1821 * InferenceV2 – field integrity checks
1922 */
20- class InferenceTest extends TestCase
23+ class InferenceResponseTest extends TestCase
2124{
2225 private function loadFromResource (string $ resourcePath ): InferenceResponse
2326 {
@@ -30,10 +33,9 @@ private function loadFromResource(string $resourcePath): InferenceResponse
3033
3134 private function readFileAsString (string $ path ): string
3235 {
33- $ fullPath = TestingUtilities::getRootDataDir () . $ path ;
34- $ this ->assertFileExists ($ fullPath , "Resource file must exist: $ path " );
36+ $ this ->assertFileExists ($ path , "Resource file must exist: $ path " );
3537
36- return file_get_contents ($ fullPath );
38+ return file_get_contents ($ path );
3739 }
3840
3941 /**
@@ -292,7 +294,7 @@ public function testRawTextsMustBeAccessible(): void
292294 $ this ->assertEquals ('This is the raw text of the first page... ' , $ first ->content );
293295
294296 foreach ($ rawText ->pages as $ page ) {
295- $ this ->assertEquals ( ' string ' , gettype ( $ page ->content ) );
297+ $ this ->assertIsString ( $ page ->content );
296298 }
297299 }
298300
@@ -301,8 +303,10 @@ public function testRawTextsMustBeAccessible(): void
301303 */
302304 public function testRstDisplayMustBeAccessible (): void
303305 {
304- $ response = $ this ->loadFromResource ('/v2/inference/standard_field_types.json ' );
305- $ expectedRst = $ this ->readFileAsString ('/v2/inference/standard_field_types.rst ' );
306+ $ response = $ this ->loadFromResource ('v2/inference/standard_field_types.json ' );
307+ $ expectedRst = $ this ->readFileAsString (
308+ \TestingUtilities::getV2DataDir () . '/inference/standard_field_types.rst '
309+ );
306310 $ inference = $ response ->inference ;
307311 $ this ->assertNotNull ($ inference );
308312 $ this ->assertEquals ($ expectedRst , strval ($ response ->inference ));
@@ -358,4 +362,32 @@ public function testCoordinatesAndLocationDataMustBeAccessible(): void
358362 $ this ->assertTrue (FieldConfidence::Low->lt ($ dateField ->confidence ));
359363 $ this ->assertEquals ('Medium ' , $ dateField ->confidence ->value );
360364 }
365+
366+ public function testRagMetadataWhenMatched ()
367+ {
368+ $ response = $ this ->loadFromResource ('v2/inference/rag_matched.json ' );
369+ $ inference = $ response ->inference ;
370+ $ this ->assertNotNull ($ inference );
371+ $ this ->assertEquals ('12345abc-1234-1234-1234-123456789abc ' , $ inference ->result ->rag ->retrievedDocumentId );
372+ }
373+
374+ public function testRagMetadataWhenNotMatched ()
375+ {
376+ $ response = $ this ->loadFromResource ('v2/inference/rag_not_matched.json ' );
377+ $ inference = $ response ->inference ;
378+ $ this ->assertNotNull ($ inference );
379+ $ this ->assertNull ($ inference ->result ->rag ->retrievedDocumentId );
380+ }
381+
382+ public function testShouldLoadWith422Error ()
383+ {
384+ $ jsonResponse = json_decode (file_get_contents (\TestingUtilities::getV2DataDir () . '/job/fail_422.json ' ), true );
385+ $ response = new JobResponse ($ jsonResponse );
386+ $ this ->assertNotNull ($ response ->job );
387+ $ this ->assertInstanceOf (ErrorResponse::class, $ response ->job ->error );
388+ $ this ->assertEquals (422 , $ response ->job ->error ->status );
389+ $ this ->assertStringStartsWith ("422- " , $ response ->job ->error ->code );
390+ $ this ->assertEquals (1 , count ($ response ->job ->error ->errors ));
391+ $ this ->assertInstanceOf (ErrorItem::class, $ response ->job ->error ->errors [0 ]);
392+ }
361393}
0 commit comments