Added DTO used to pass filtering params to VisitsTracker

This commit is contained in:
Alejandro Celaya
2018-11-27 21:09:27 +01:00
parent 03ee46d903
commit 45254606d4
8 changed files with 69 additions and 41 deletions

View File

@@ -4,12 +4,12 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Rest\Action\Visit;
use Cake\Chronos\Chronos;
use Exception;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Model\VisitsParams;
use Shlinkio\Shlink\Core\Service\VisitsTracker;
use Shlinkio\Shlink\Rest\Action\Visit\GetVisitsAction;
use Zend\Diactoros\ServerRequestFactory;
@@ -33,7 +33,7 @@ class GetVisitsActionTest extends TestCase
public function providingCorrectShortCodeReturnsVisits()
{
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willReturn([])
$this->visitsTracker->info($shortCode, Argument::type(VisitsParams::class))->willReturn([])
->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
@@ -46,7 +46,7 @@ class GetVisitsActionTest extends TestCase
public function providingInvalidShortCodeReturnsError()
{
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willThrow(
$this->visitsTracker->info($shortCode, Argument::type(VisitsParams::class))->willThrow(
InvalidArgumentException::class
)->shouldBeCalledOnce();
@@ -54,27 +54,15 @@ class GetVisitsActionTest extends TestCase
$this->assertEquals(404, $response->getStatusCode());
}
/**
* @test
*/
public function unexpectedExceptionWillReturnError()
{
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willThrow(
Exception::class
)->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(500, $response->getStatusCode());
}
/**
* @test
*/
public function datesAreReadFromQuery()
{
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, new DateRange(null, Chronos::parse('2016-01-01 00:00:00')))
$this->visitsTracker->info($shortCode, new VisitsParams(
new DateRange(null, Chronos::parse('2016-01-01 00:00:00'))
))
->willReturn([])
->shouldBeCalledOnce();