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-21 11:49:47 -05:00
|
|
|
private MockObject $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([]);
|
|
|
|
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|