2016-07-31 00:01:07 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-31 00:01:07 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Core\Service;
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManager;
|
2017-03-24 22:34:18 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-07-31 00:01:07 +03:00
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
|
|
|
use Shlinkio\Shlink\Core\Repository\VisitRepository;
|
|
|
|
use Shlinkio\Shlink\Core\Service\VisitService;
|
|
|
|
|
|
|
|
class VisitServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var VisitService
|
|
|
|
*/
|
|
|
|
protected $visitService;
|
|
|
|
/**
|
|
|
|
* @var ObjectProphecy
|
|
|
|
*/
|
|
|
|
protected $em;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->em = $this->prophesize(EntityManager::class);
|
|
|
|
$this->visitService = new VisitService($this->em->reveal());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function saveVisitsPersistsProvidedVisit()
|
|
|
|
{
|
|
|
|
$visit = new Visit();
|
|
|
|
$this->em->persist($visit)->shouldBeCalledTimes(1);
|
|
|
|
$this->em->flush()->shouldBeCalledTimes(1);
|
|
|
|
$this->visitService->saveVisit($visit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function getUnlocatedVisitsFallbacksToRepository()
|
|
|
|
{
|
|
|
|
$repo = $this->prophesize(VisitRepository::class);
|
|
|
|
$repo->findUnlocatedVisits()->shouldBeCalledTimes(1);
|
|
|
|
$this->em->getRepository(Visit::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
|
|
|
|
$this->visitService->getUnlocatedVisits();
|
|
|
|
}
|
|
|
|
}
|