2016-06-18 02:43:29 -05:00
|
|
|
<?php
|
|
|
|
namespace AcelayaTest\UrlShortener\Service;
|
|
|
|
|
|
|
|
use Acelaya\UrlShortener\Entity\ShortUrl;
|
2016-07-04 02:18:10 -05:00
|
|
|
use Acelaya\UrlShortener\Repository\ShortUrlRepository;
|
2016-06-18 02:43:29 -05:00
|
|
|
use Acelaya\UrlShortener\Service\ShortUrlService;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use PHPUnit_Framework_TestCase as TestCase;
|
2016-07-04 02:18:10 -05:00
|
|
|
use Prophecy\Argument;
|
2016-06-18 02:43:29 -05:00
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
|
|
|
|
class ShortUrlServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ShortUrlService
|
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
/**
|
|
|
|
* @var ObjectProphecy|EntityManagerInterface
|
|
|
|
*/
|
|
|
|
protected $em;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->em = $this->prophesize(EntityManagerInterface::class);
|
|
|
|
$this->service = new ShortUrlService($this->em->reveal());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function listedUrlsAreReturnedFromEntityManager()
|
|
|
|
{
|
2016-07-04 02:18:10 -05:00
|
|
|
$list = [
|
2016-06-18 02:43:29 -05:00
|
|
|
new ShortUrl(),
|
|
|
|
new ShortUrl(),
|
|
|
|
new ShortUrl(),
|
|
|
|
new ShortUrl(),
|
2016-07-04 02:18:10 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
$repo = $this->prophesize(ShortUrlRepository::class);
|
|
|
|
$repo->findList(Argument::cetera())->willReturn($list)->shouldBeCalledTimes(1);
|
|
|
|
$repo->countList(Argument::cetera())->willReturn(count($list))->shouldBeCalledTimes(1);
|
2016-06-18 02:43:29 -05:00
|
|
|
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
|
|
|
|
|
|
|
$list = $this->service->listShortUrls();
|
2016-07-04 02:18:10 -05:00
|
|
|
$this->assertEquals(4, $list->getCurrentItemCount());
|
2016-06-18 02:43:29 -05:00
|
|
|
}
|
|
|
|
}
|