mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-31 19:26:58 -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;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Crawling\CrawlingHelper;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
||||
|
||||
class CrawlingHelperTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
private CrawlingHelper $helper;
|
||||
private ObjectProphecy $em;
|
||||
private MockObject $em;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->em = $this->prophesize(EntityManagerInterface::class);
|
||||
$this->helper = new CrawlingHelper($this->em->reveal());
|
||||
$this->em = $this->createMock(EntityManagerInterface::class);
|
||||
$this->helper = new CrawlingHelper($this->em);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function listCrawlableShortCodesDelegatesIntoRepository(): void
|
||||
{
|
||||
$repo = $this->prophesize(ShortUrlRepositoryInterface::class);
|
||||
$findCrawlableShortCodes = $repo->findCrawlableShortCodes()->willReturn([]);
|
||||
$getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
||||
$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,
|
||||
);
|
||||
|
||||
$result = $this->helper->listCrawlableShortCodes();
|
||||
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