Skip to content

Commit b4b45a6

Browse files
authored
Merge pull request #28 from silverstripeltd/bugfix/logger-warnings
Update logger class method for warnings
2 parents 087af25 + f87d529 commit b4b45a6

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

src/Service/BifrostService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,15 @@ private function getContentMapForDocuments(string $indexSuffix, array $documents
533533
$indexes = $this->getConfiguration()->getIndexConfigurationsForDocument($document);
534534

535535
if (!$indexes) {
536-
Injector::inst()->get(LoggerInterface::class)->warn(
536+
Injector::inst()->get(LoggerInterface::class)->warning(
537537
sprintf('No valid indexes found for document %s, skipping...', $document->getIdentifier())
538538
);
539539

540540
continue;
541541
}
542542

543543
if (!in_array($indexSuffix, array_keys($indexes), true)) {
544-
Injector::inst()->get(LoggerInterface::class)->warn(
544+
Injector::inst()->get(LoggerInterface::class)->warning(
545545
sprintf(
546546
'%s is not a valid index for document %s, skipping...',
547547
$indexSuffix,

tests/Service/BifrostServiceTest.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use SilverStripe\Forager\Extensions\SearchServiceExtension;
1616
use SilverStripe\Forager\Service\DocumentBuilder;
1717
use SilverStripe\Forager\Service\IndexConfiguration;
18+
use SilverStripe\Forager\Service\IndexData;
1819
use SilverStripe\ForagerBifrost\Service\BifrostService;
1920
use SilverStripe\ForagerBifrost\Service\ClientFactory;
2021
use 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

Comments
 (0)