Completed
Push — master ( f7424d...b53e51 )
by Alejandro
07:43
created

ListShortCodesActionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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