setTitle('Post A') ->withTags(['Drupal 8']) ->create(); $postA->save(); $postB = (new 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()); } protected function setUp() { parent::setUp(); $this->relatedPostsRepository = $this->container->get(RelatedPostsRepository::class); } }