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

ListShortCodesActionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 52.83 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
dl 28
loc 53
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A properListReturnsSuccessResponse() 14 14 1
A anExceptionsReturnsErrorResponse() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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