1
|
|
|
<?php |
2
|
|
|
namespace ShlinkioTest\Shlink\Rest\Action; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
6
|
|
|
use Shlinkio\Shlink\Core\Service\ShortUrlService; |
7
|
|
|
use Shlinkio\Shlink\Rest\Action\ListShortcodesAction; |
8
|
|
|
use ShlinkioTest\Shlink\Common\Util\TestUtils; |
9
|
|
|
use Zend\Diactoros\ServerRequestFactory; |
10
|
|
|
use Zend\I18n\Translator\Translator; |
11
|
|
|
use Zend\Paginator\Adapter\ArrayAdapter; |
12
|
|
|
use Zend\Paginator\Paginator; |
13
|
|
|
|
14
|
|
|
class ListShortCodesActionTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var ListShortcodesAction |
18
|
|
|
*/ |
19
|
|
|
protected $action; |
20
|
|
|
/** |
21
|
|
|
* @var ObjectProphecy |
22
|
|
|
*/ |
23
|
|
|
protected $service; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->service = $this->prophesize(ShortUrlService::class); |
28
|
|
|
$this->action = new ListShortcodesAction($this->service->reveal(), Translator::factory([])); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
public function properListReturnsSuccessResponse() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$page = 3; |
37
|
|
|
$this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter())) |
38
|
|
|
->shouldBeCalledTimes(1); |
39
|
|
|
|
40
|
|
|
$response = $this->action->process( |
41
|
|
|
ServerRequestFactory::fromGlobals()->withQueryParams([ |
42
|
|
|
'page' => $page, |
43
|
|
|
]), |
44
|
|
|
TestUtils::createDelegateMock()->reveal() |
45
|
|
|
); |
46
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @test |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function anExceptionsReturnsErrorResponse() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$page = 3; |
55
|
|
|
$this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class) |
56
|
|
|
->shouldBeCalledTimes(1); |
57
|
|
|
|
58
|
|
|
$response = $this->action->process( |
59
|
|
|
ServerRequestFactory::fromGlobals()->withQueryParams([ |
60
|
|
|
'page' => $page, |
61
|
|
|
]), |
62
|
|
|
TestUtils::createDelegateMock()->reveal() |
63
|
|
|
); |
64
|
|
|
$this->assertEquals(500, $response->getStatusCode()); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.