Return an empty Collection if there are no posts
Return an empty Collection if there are no related posts for the given post. References #3
This commit is contained in:
parent
059e237600
commit
ae0024f335
2 changed files with 32 additions and 0 deletions
web/modules/custom/blog/tests/src/Kernel
|
@ -33,6 +33,25 @@ final class RelatedPostsTest extends PostTestBase {
|
|||
$this->assertSame('Post B', $relatedPosts->first()->label());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_returns_an_empty_collection_if_there_are_no_related_posts(): void {
|
||||
$postA = $this->postFactory
|
||||
->setTitle('Drupal 8 post')
|
||||
->withTags(['Drupal 8'])
|
||||
->create();
|
||||
$postA->save();
|
||||
|
||||
$postB = $this->postFactory
|
||||
->setTitle('Drupal 9 post')
|
||||
->withTags(['Drupal 9'])
|
||||
->create();
|
||||
$postB->save();
|
||||
|
||||
$relatedPosts = $this->relatedPostsRepository->getFor($postA);
|
||||
|
||||
$this->assertEmpty($relatedPosts);
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue