Skip to content

Commit

Permalink
Fix and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Dunn committed Apr 23, 2024
1 parent 0838640 commit a1e4daa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/DataObject/DataObjectDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public function onAddToSearchIndexes(string $event): void

$currentDataObject = $this->getDataObject();

$liveDataObject = DataObject::get($currentDataObject->ClassName)->byID($currentDataObject->ID);
$liveDataObject = $currentDataObject ? DataObject::get($currentDataObject->ClassName)->byID($currentDataObject->ID) : null;

if (!$liveDataObject) {
// unlikely case as indexer calls 'shouldIndex' immediately prior to this
Expand Down
15 changes: 11 additions & 4 deletions tests/DataObject/DataObjectDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,15 @@ public function testExtensionRequired(): void

public function testEvents(): void
{
$dataObject = $this->objFromFixture(DataObjectFake::class, 'one');

$mock = $this->getMockBuilder(DataObjectDocument::class)
->onlyMethods(['markIndexed'])
->disableOriginalConstructor()
->getMock();

$mock->setDataObject($dataObject);

$mock->expects($this->exactly(2))
->method('markIndexed');

Expand All @@ -619,11 +624,13 @@ public function testDeletedDataObject(): void
$this->assertEquals($id, $serialDoc->getDataObject()->ID);

$doc->setShouldFallbackToLatestVersion(false);
$this->expectExceptionMessage(
sprintf('DataObject %s : %s does not exist', DataObjectFakeVersioned::class, $id)
);

unserialize(serialize($doc));
$serialDoc = unserialize(serialize($doc));

// the data object does not exist (it has been deleted), but we should still return some basic details
// for attempting a delete from elastic
$this->assertEquals('silverstripe_searchservice_tests_fake_dataobjectfakeversioned_1', $serialDoc->getIdentifier());
$this->assertEquals(DataObjectFakeVersioned::class, $serialDoc->getSourceClass());
}

}

0 comments on commit a1e4daa

Please sign in to comment.