Completed
Pull Request — master (#148)
by Alejandro
04:08
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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Rest\Action\ShortCode;
5
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Prophecy\ObjectProphecy;
8
use Shlinkio\Shlink\Core\Service\ShortUrlService;
9
use Shlinkio\Shlink\Rest\Action\ShortCode\ListShortCodesAction;
10
use Zend\Diactoros\ServerRequestFactory;
11
use Zend\I18n\Translator\Translator;
12
use Zend\Paginator\Adapter\ArrayAdapter;
13
use Zend\Paginator\Paginator;
14
15
class ListShortCodesActionTest extends TestCase
16
{
17
    /**
18
     * @var ListShortCodesAction
19
     */
20
    protected $action;
21
    /**
22
     * @var ObjectProphecy
23
     */
24
    protected $service;
25
26
    public function setUp()
27
    {
28
        $this->service = $this->prophesize(ShortUrlService::class);
29
        $this->action = new ListShortCodesAction($this->service->reveal(), Translator::factory([]));
30
    }
31
32
    /**
33
     * @test
34
     */
35 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...
36
    {
37
        $page = 3;
38
        $this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
39
                                                            ->shouldBeCalledTimes(1);
40
41
        $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
42
            'page' => $page,
43
        ]));
44
        $this->assertEquals(200, $response->getStatusCode());
45
    }
46
47
    /**
48
     * @test
49
     */
50 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...
51
    {
52
        $page = 3;
53
        $this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class)
54
                                                            ->shouldBeCalledTimes(1);
55
56
        $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
57
            'page' => $page,
58
        ]));
59
        $this->assertEquals(500, $response->getStatusCode());
60
    }
61
}
62