mirror of
https://github.com/shlinkio/shlink.git
synced 2026-10-12 21:31:58 -05:00
Added more tests
This commit is contained in:
1 parent
bb11269146
commit
83352f0af9
3 files changed
+77
-1
No files matched your search
@@ -42,7 +42,7 @@ class VisitsTracker implements VisitsTrackerInterface
|
|||||||
$visit = new Visit();
|
$visit = new Visit();
|
||||||
$visit->setShortUrl($shortUrl)
|
$visit->setShortUrl($shortUrl)
|
||||||
->setUserAgent($this->getArrayValue($visitorData, 'HTTP_USER_AGENT'))
|
->setUserAgent($this->getArrayValue($visitorData, 'HTTP_USER_AGENT'))
|
||||||
->setReferer($this->getArrayValue($visitorData, 'REFERER'))
|
->setReferer($this->getArrayValue($visitorData, 'HTTP_REFERER'))
|
||||||
->setRemoteAddr($this->getArrayValue($visitorData, 'REMOTE_ADDR'));
|
->setRemoteAddr($this->getArrayValue($visitorData, 'REMOTE_ADDR'));
|
||||||
$this->em->persist($visit);
|
$this->em->persist($visit);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
namespace AcelayaTest\UrlShortener\Factory;
|
||||||
|
|
||||||
|
use Acelaya\UrlShortener\Factory\CacheFactory;
|
||||||
|
use Doctrine\Common\Cache\ApcuCache;
|
||||||
|
use Doctrine\Common\Cache\ArrayCache;
|
||||||
|
use PHPUnit_Framework_TestCase as TestCase;
|
||||||
|
use Zend\ServiceManager\ServiceManager;
|
||||||
|
|
||||||
|
class CacheFactoryTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var CacheFactory
|
||||||
|
*/
|
||||||
|
protected $factory;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->factory = new CacheFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
putenv('APP_ENV');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function productionReturnsApcAdapter()
|
||||||
|
{
|
||||||
|
putenv('APP_ENV=pro');
|
||||||
|
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
||||||
|
$this->assertInstanceOf(ApcuCache::class, $instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function developmentReturnsArrayAdapter()
|
||||||
|
{
|
||||||
|
putenv('APP_ENV=dev');
|
||||||
|
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
||||||
|
$this->assertInstanceOf(ArrayCache::class, $instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
namespace AcelayaTest\UrlShortener\Service;
|
||||||
|
|
||||||
|
use Acelaya\UrlShortener\Entity\ShortUrl;
|
||||||
|
use Acelaya\UrlShortener\Service\VisitsTracker;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use PHPUnit_Framework_TestCase as TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user