2021-05-22 02:34:42 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Crawling;
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2022-10-21 11:49:47 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2021-05-22 02:34:42 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Crawling\CrawlingHelper;
|
2022-09-23 12:03:32 -05:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
2022-09-23 11:24:14 -05:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
2021-05-22 02:34:42 -05:00
|
|
|
|
|
|
|
class CrawlingHelperTest extends TestCase
|
|
|
|
{
|
|
|
|
private CrawlingHelper $helper;
|
2022-10-24 12:53:13 -05:00
|
|
|
private MockObject & EntityManagerInterface $em;
|
2021-05-22 02:34:42 -05:00
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
2022-10-21 11:49:47 -05:00
|
|
|
$this->em = $this->createMock(EntityManagerInterface::class);
|
|
|
|
$this->helper = new CrawlingHelper($this->em);
|
2021-05-22 02:34:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function listCrawlableShortCodesDelegatesIntoRepository(): void
|
|
|
|
{
|
2022-10-21 11:49:47 -05:00
|
|
|
$repo = $this->createMock(ShortUrlRepositoryInterface::class);
|
|
|
|
$repo->expects($this->once())->method('findCrawlableShortCodes')->willReturn([]);
|
2022-10-23 11:15:57 -05:00
|
|
|
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($repo);
|
2021-05-22 02:34:42 -05:00
|
|
|
|
|
|
|
$result = $this->helper->listCrawlableShortCodes();
|
|
|
|
foreach ($result as $shortCode) {
|
2022-10-21 11:49:47 -05:00
|
|
|
// $result is a generator and therefore, it needs to be iterated
|
2021-05-22 02:34:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|