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