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