2021-05-22 10:34:42 +03:00
|
|
|
<?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;
|
2022-09-23 20:03:32 +03:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
2022-09-23 19:24:14 +03:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
2021-05-22 10:34:42 +03:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|