mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-05 21:53:22 -06:00
Migrated CrawlingHelperTest to use PHPUnit mocks
This commit is contained in:
parent
29d50cabc2
commit
148f7a9cfe
@ -5,39 +5,35 @@ declare(strict_types=1);
|
|||||||
namespace ShlinkioTest\Shlink\Core\Crawling;
|
namespace ShlinkioTest\Shlink\Core\Crawling;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Shlinkio\Shlink\Core\Crawling\CrawlingHelper;
|
use Shlinkio\Shlink\Core\Crawling\CrawlingHelper;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
||||||
|
|
||||||
class CrawlingHelperTest extends TestCase
|
class CrawlingHelperTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private CrawlingHelper $helper;
|
private CrawlingHelper $helper;
|
||||||
private ObjectProphecy $em;
|
private MockObject $em;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->em = $this->prophesize(EntityManagerInterface::class);
|
$this->em = $this->createMock(EntityManagerInterface::class);
|
||||||
$this->helper = new CrawlingHelper($this->em->reveal());
|
$this->helper = new CrawlingHelper($this->em);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function listCrawlableShortCodesDelegatesIntoRepository(): void
|
public function listCrawlableShortCodesDelegatesIntoRepository(): void
|
||||||
{
|
{
|
||||||
$repo = $this->prophesize(ShortUrlRepositoryInterface::class);
|
$repo = $this->createMock(ShortUrlRepositoryInterface::class);
|
||||||
$findCrawlableShortCodes = $repo->findCrawlableShortCodes()->willReturn([]);
|
$repo->expects($this->once())->method('findCrawlableShortCodes')->willReturn([]);
|
||||||
$getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn(
|
||||||
|
$repo,
|
||||||
|
);
|
||||||
|
|
||||||
$result = $this->helper->listCrawlableShortCodes();
|
$result = $this->helper->listCrawlableShortCodes();
|
||||||
foreach ($result as $shortCode) {
|
foreach ($result as $shortCode) {
|
||||||
// Result is a generator and therefore, it needs to be iterated
|
// $result is a generator and therefore, it needs to be iterated
|
||||||
}
|
}
|
||||||
|
|
||||||
$findCrawlableShortCodes->shouldHaveBeenCalledOnce();
|
|
||||||
$getRepo->shouldHaveBeenCalledOnce();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user