em = $this->prophesize(EntityManagerInterface::class); $this->helper = new CrawlingHelper($this->em->reveal()); } /** @test */ public function listCrawlableShortCodesDelegatesIntoRepository(): void { $repo = $this->prophesize(ShortUrlRepositoryInterface::class); $findCrawlableShortCodes = $repo->findCrawlableShortCodes()->willReturn([]); $getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); $result = $this->helper->listCrawlableShortCodes(); foreach ($result as $shortCode) { // Result is a generator and therefore, it needs to be iterated } $findCrawlableShortCodes->shouldHaveBeenCalledOnce(); $getRepo->shouldHaveBeenCalledOnce(); } }