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

31 lines
943 B
PHP
Raw Normal View History

2016-05-01 18:54:56 +03:00
<?php
2016-07-19 19:01:39 +03:00
namespace ShlinkioTest\Shlink\Core\Service;
2016-05-01 18:54:56 +03:00
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use PHPUnit_Framework_TestCase as TestCase;
use Prophecy\Argument;
2016-07-19 19:01:39 +03:00
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Service\VisitsTracker;
2016-05-01 18:54:56 +03:00
class VisitsTrackerTest extends TestCase
{
/**
* @test
*/
public function trackPersistsVisit()
{
$shortCode = '123ABC';
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl());
$em = $this->prophesize(EntityManager::class);
$em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
$em->persist(Argument::any())->shouldBeCalledTimes(1);
$em->flush()->shouldBeCalledTimes(1);
$visitsTracker = new VisitsTracker($em->reveal());
$visitsTracker->track($shortCode);
}
}