shlink/module/Core/test/Crawling/CrawlingHelperTest.php

43 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Crawling;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Crawling\CrawlingHelper;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
class CrawlingHelperTest extends TestCase
{
use ProphecyTrait;
private CrawlingHelper $helper;
private ObjectProphecy $em;
protected function setUp(): void
{
$this->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();
}
}