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

67 lines
1.9 KiB
PHP
Raw Normal View History

2016-07-31 09:16:26 -05:00
<?php
namespace ShlinkioTest\Shlink\Rest\Action;
2017-03-24 14:34:18 -05:00
use PHPUnit\Framework\TestCase;
2016-07-31 09:16:26 -05:00
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\ListShortcodesAction;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
use Zend\Paginator\Adapter\ArrayAdapter;
use Zend\Paginator\Paginator;
class ListShortcodesActionTest extends TestCase
{
/**
* @var ListShortcodesAction
*/
protected $action;
/**
* @var ObjectProphecy
*/
protected $service;
public function setUp()
{
$this->service = $this->prophesize(ShortUrlService::class);
$this->action = new ListShortcodesAction($this->service->reveal(), Translator::factory([]));
}
/**
* @test
*/
public function properListReturnsSuccessResponse()
{
$page = 3;
$this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1);
2016-07-31 09:16:26 -05:00
$response = $this->action->__invoke(
ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
]),
new Response()
);
$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 09:16:26 -05:00
$response = $this->action->__invoke(
ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
]),
new Response()
);
$this->assertEquals(500, $response->getStatusCode());
}
}