shlink/module/Core/test/Service/VisitServiceTest.php

55 lines
1.5 KiB
PHP
Raw Normal View History

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;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
2016-07-30 16:01:07 -05:00
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Entity\VisitLocation;
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
*/
public function locateVisitPersistsProvidedVisit()
2016-07-30 16:01:07 -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();
$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();
}
}