shlink/module/Rest/test/Action/ListShortCodesActionTest.php

62 lines
1.8 KiB
PHP
Raw Normal View History

2016-07-31 17:16:26 +03:00
<?php
2017-10-12 11:13:20 +03:00
declare(strict_types=1);
2016-07-31 17:16:26 +03:00
namespace ShlinkioTest\Shlink\Rest\Action;
2017-03-24 22:34:18 +03:00
use PHPUnit\Framework\TestCase;
2016-07-31 17:16:26 +03:00
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\ShortUrlService;
2018-05-03 13:19:51 +03:00
use Shlinkio\Shlink\Rest\Action\ListShortCodesAction;
2016-07-31 17:16:26 +03:00
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
use Zend\Paginator\Adapter\ArrayAdapter;
use Zend\Paginator\Paginator;
class ListShortCodesActionTest extends TestCase
2016-07-31 17:16:26 +03:00
{
/**
2018-05-03 13:19:51 +03:00
* @var ListShortCodesAction
2016-07-31 17:16:26 +03:00
*/
protected $action;
/**
* @var ObjectProphecy
*/
protected $service;
public function setUp()
{
$this->service = $this->prophesize(ShortUrlService::class);
2018-05-03 13:19:51 +03:00
$this->action = new ListShortCodesAction($this->service->reveal(), Translator::factory([]));
2016-07-31 17:16:26 +03:00
}
/**
* @test
*/
public function properListReturnsSuccessResponse()
{
$page = 3;
$this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1);
2016-07-31 17:16:26 +03:00
2018-03-26 20:02:41 +03:00
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
]));
2016-07-31 17:16:26 +03:00
$this->assertEquals(200, $response->getStatusCode());
}
/**
* @test
*/
public function anExceptionsReturnsErrorResponse()
{
$page = 3;
$this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class)
->shouldBeCalledTimes(1);
2016-07-31 17:16:26 +03:00
2018-03-26 20:02:41 +03:00
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
]));
2016-07-31 17:16:26 +03:00
$this->assertEquals(500, $response->getStatusCode());
}
}