2016-07-30 16:01:07 -05:00
|
|
|
<?php
|
2017-10-12 03:13:20 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-30 16:01:07 -05:00
|
|
|
namespace ShlinkioTest\Shlink\Core\Service;
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManager;
|
2017-03-24 14:34:18 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-07-30 16:01:07 -05:00
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
2018-10-28 10:20:10 -05:00
|
|
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
2016-07-30 16:01:07 -05:00
|
|
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
2018-11-17 00:47:42 -06:00
|
|
|
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
2018-10-28 10:20:10 -05:00
|
|
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
2016-07-30 16:01:07 -05:00
|
|
|
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
|
|
|
|
*/
|
2018-11-17 00:47:42 -06:00
|
|
|
public function locateVisitPersistsProvidedVisit()
|
2016-07-30 16:01:07 -05:00
|
|
|
{
|
2018-10-28 10:20:10 -05:00
|
|
|
$visit = new Visit(new ShortUrl(''), Visitor::emptyInstance());
|
2018-11-11 06:18:21 -06:00
|
|
|
$this->em->persist($visit)->shouldBeCalledOnce();
|
|
|
|
$this->em->flush()->shouldBeCalledOnce();
|
2018-11-17 00:47:42 -06:00
|
|
|
$this->visitService->locateVisit($visit, new VisitLocation([]));
|
2016-07-30 16:01:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function getUnlocatedVisitsFallbacksToRepository()
|
|
|
|
{
|
|
|
|
$repo = $this->prophesize(VisitRepository::class);
|
2018-11-11 06:18:21 -06:00
|
|
|
$repo->findUnlocatedVisits()->shouldBeCalledOnce();
|
|
|
|
$this->em->getRepository(Visit::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
|
2016-07-30 16:01:07 -05:00
|
|
|
$this->visitService->getUnlocatedVisits();
|
|
|
|
}
|
|
|
|
}
|