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