1515use SilverStripe \Forager \Extensions \SearchServiceExtension ;
1616use SilverStripe \Forager \Service \DocumentBuilder ;
1717use SilverStripe \Forager \Service \IndexConfiguration ;
18+ use SilverStripe \Forager \Service \IndexData ;
1819use SilverStripe \ForagerBifrost \Service \BifrostService ;
1920use SilverStripe \ForagerBifrost \Service \ClientFactory ;
2021use SilverStripe \ForagerBifrost \Tests \Fake \DataObjectFake ;
@@ -255,8 +256,14 @@ public function testGetContentMapForDocuments(): void
255256 $ reflectionMethod = new ReflectionMethod (BifrostService::class, 'getContentMapForDocuments ' );
256257 $ reflectionMethod ->setAccessible (true );
257258
258- // Invoke our method which will trigger 2 API calls, and we're expecting the second API call to trigger an error
259- $ this ->assertEquals ($ expectedMap , $ reflectionMethod ->invoke ($ this ->searchService , 'content ' , $ documents ));
259+ $ indexData = $ this ->searchService ->getConfiguration ()->getIndexDataForSuffix ('content ' );
260+ $ indexData ->withIndexContext (
261+ function (IndexData $ index ) use ($ expectedMap , $ reflectionMethod , $ documents ): void {
262+ // Invoke our method which will trigger 2 API calls, and we're expecting the second API call to trigger an error
263+ $ this ->assertEquals ($ expectedMap , $ reflectionMethod ->invoke ($ this ->searchService , 'content ' , $ documents ));
264+
265+ }
266+ );
260267 }
261268
262269 public function testConfigureNewField (): void
@@ -700,8 +707,14 @@ public function testAddDocuments(): void
700707 'doc-123 ' ,
701708 '321 ' ,
702709 ];
710+ $ resultIds = [];
703711
704- $ resultIds = $ this ->searchService ->addDocuments ('content ' , $ documents );
712+ $ indexData = $ this ->searchService ->getConfiguration ()->getIndexDataForSuffix ('content ' );
713+ $ indexData ->withIndexContext (
714+ function (IndexData $ index ) use (&$ resultIds , $ documents ): void {
715+ $ resultIds = $ this ->searchService ->addDocuments ('content ' , $ documents );
716+ }
717+ );
705718
706719 $ this ->assertEqualsCanonicalizing ($ expectedIds , $ resultIds );
707720 // And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
@@ -738,7 +751,12 @@ public function testAddDocument(): void
738751 // Append this mock response to our stack
739752 $ this ->mock ->append (new Response (200 , $ headers , $ body ));
740753
741- $ resultId = $ this ->searchService ->addDocument ('content ' , $ document );
754+ $ indexData = $ this ->searchService ->getConfiguration ()->getIndexDataForSuffix ('content ' );
755+ $ indexData ->withIndexContext (
756+ function (IndexData $ index ) use (&$ resultId , $ document ): void {
757+ $ resultId = $ this ->searchService ->addDocument ('content ' , $ document );
758+ }
759+ );
742760
743761 $ this ->assertEquals ('doc-123 ' , $ resultId );
744762 // And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
@@ -761,8 +779,13 @@ public function testAddDocumentEmpty(): void
761779 // Append this mock response to our stack
762780 $ this ->mock ->append (new Response (200 , $ headers , $ body ));
763781
764- // Kinda just checking that the array_shift correctly returns null if no results were presented from Bifrost
765- $ resultId = $ this ->searchService ->addDocument ('content ' , $ document );
782+ $ indexData = $ this ->searchService ->getConfiguration ()->getIndexDataForSuffix ('content ' );
783+ $ indexData ->withIndexContext (
784+ function (IndexData $ index ) use (&$ resultId , $ document ): void {
785+ // Kinda just checking that the array_shift correctly returns null if no results were presented from Bifrost
786+ $ resultId = $ this ->searchService ->addDocument ('content ' , $ document );
787+ }
788+ );
766789
767790 $ this ->assertNull ($ resultId );
768791 // And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
@@ -817,8 +840,14 @@ public function testRemoveDocuments(): void
817840 sprintf ('silverstripe_searchservice_tests_fake_dataobjectfake_%s ' , $ documentThree ->ID ),
818841 '123 ' ,
819842 ];
843+ $ resultIds = [];
820844
821- $ resultIds = $ this ->searchService ->addDocuments ('content ' , $ documents );
845+ $ indexData = $ this ->searchService ->getConfiguration ()->getIndexDataForSuffix ('content ' );
846+ $ indexData ->withIndexContext (
847+ function (IndexData $ index ) use (&$ resultIds , $ documents ): void {
848+ $ resultIds = $ this ->searchService ->addDocuments ('content ' , $ documents );
849+ }
850+ );
822851
823852 $ this ->assertEqualsCanonicalizing ($ expectedIds , $ resultIds );
824853 // And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
0 commit comments