postFactory ->setTitle('Post A') ->withTags(['Drupal 8']) ->create(); $postA->save(); $postB = $this->postFactory ->setTitle('Post B') ->withTags(['Drupal 8']) ->create(); $postB->save(); $relatedPosts = $this->relatedPostsRepository->getFor($postA); $this->assertCount(1, $relatedPosts); $this->assertSame('Post B', $relatedPosts->first()->label()); } /** @test */ public function unpublished_posts_are_not_returned(): void { $this->markTestSkipped(); } /** @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(); $this->postFactory = $this->container->get(PostFactory::class); $this->relatedPostsRepository = $this->container->get(RelatedPostsRepository::class); } }