Completed
Pull Request — master (#213)
by Alejandro
04:40
created

ListShortUrlsActionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 44 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 22
loc 50
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A properListReturnsSuccessResponse() 11 11 1
A anExceptionsReturnsErrorResponse() 11 11 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
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
5
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Prophecy\ObjectProphecy;
8
use Shlinkio\Shlink\Core\Service\ShortUrlService;
9
use Shlinkio\Shlink\Rest\Action\ShortUrl\ListShortUrlsAction;
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 ListShortUrlsActionTest extends TestCase
16
{
17
    /**
18
     * @var ListShortUrlsAction
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 ListShortUrlsAction($this->service->reveal(), Translator::factory([]), [
30
            'hostname' => 'doma.in',
31
            'schema' => 'https',
32
        ]);
33
    }
34
35
    /**
36
     * @test
37
     */
38 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...
39
    {
40
        $page = 3;
41
        $this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
42
                                                            ->shouldBeCalledTimes(1);
43
44
        $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
45
            'page' => $page,
46
        ]));
47
        $this->assertEquals(200, $response->getStatusCode());
48
    }
49
50
    /**
51
     * @test
52
     */
53 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...
54
    {
55
        $page = 3;
56
        $this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class)
57
                                                            ->shouldBeCalledTimes(1);
58
59
        $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
60
            'page' => $page,
61
        ]));
62
        $this->assertEquals(500, $response->getStatusCode());
63
    }
64
}
65