Skip to content

Commit d55a822

Browse files
committed
Reinstate deleted unit test
1 parent 66400b8 commit d55a822

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

tests/DataObject/DataObjectFetcherTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,43 @@ class DataObjectFetcherTest extends SearchServiceTest
3838
Subsite::class,
3939
];
4040

41+
public function testFetch(): void
42+
{
43+
$fetcher = DataObjectFetcher::create(DataObjectFake::class);
44+
/** @var DataObjectDocument[] $documents */
45+
$documents = $fetcher->fetch();
46+
47+
// Quick sanity check to make sure we have the correct number of documents
48+
$this->assertCount(3, $documents);
49+
50+
// Now start building out a basic $expectedDocuments, which is just going to be a combination of the ClassName
51+
// and Title
52+
$expectedDocuments = [
53+
sprintf('%s-Dataobject one', DataObjectFake::class),
54+
sprintf('%s-Dataobject two', DataObjectFake::class),
55+
sprintf('%s-Dataobject three', DataObjectFake::class),
56+
];
57+
58+
$resultDocuments = [];
59+
60+
foreach ($documents as $document) {
61+
// We expect each of our Documents to be a DataObjectDocument specifically
62+
$this->assertInstanceOf(DataObjectDocument::class, $document);
63+
64+
// And now let's start collating our ClassName/Title data
65+
$resultDocuments[] = sprintf('%s-%s', $document->getSourceClass(), $document->getDataObject()?->Title);
66+
}
67+
68+
$this->assertEqualsCanonicalizing($expectedDocuments, $resultDocuments);
69+
70+
// And then just a quick extra sanity check that fetching 2 Documents only returns 2 Documents
71+
$documents = $fetcher->fetch(2);
72+
73+
$this->assertCount(2, $documents);
74+
}
4175

4276
/**
43-
* This tests that we can fetch all documents when processed in batches.
77+
* This tests that we fetch all documents when processed in batches.
4478
*/
4579
public function testFetchBatch(): void
4680
{

0 commit comments

Comments
 (0)