GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#225)
by
unknown
11:59
created

KnpPaginatorFactoryTest::testSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 68
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 68
rs 9.2448
cc 1
eloc 20
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Hateoas\Tests\Representation\Factory;
4
5
use Hateoas\Configuration\Route;
6
use Hateoas\Representation\CollectionRepresentation;
7
use Hateoas\Representation\Factory\KnpPaginatorFactory;
8
use Hateoas\Tests\Representation\RepresentationTestCase;
9
use Knp\Component\Pager\Paginator;
10
11
class KnpPaginatorFactoryTest extends RepresentationTestCase {
12
13
    public function test()
14
    {
15
16
        $results = array(
17
            'Achille',
18
            'Skineur'
19
        );
20
21
        $pagerProhecy = $this->prophesize('Knp\Component\Pager\Pagination\SlidingPagination');
22
        $pagerProhecy->getItems()->willReturn($results);
23
        $pagerProhecy->getCurrentPageNumber()->willReturn(1);
24
        $pagerProhecy->getItemNumberPerPage()->willReturn(20);
25
        $pagerProhecy->getPaginationData()->willReturn(array('pageCount' => 3));
26
        $pagerProhecy->getTotalItemCount()->willReturn(50);
27
28
        $factory = new KnpPaginatorFactory('page', 'limit');
29
30
        $represention1 =  $factory->createRepresentation(
31
            $pagerProhecy->reveal(),
32
            new Route(
33
                'users',
34
                array(
35
                    'query' => 'hateoas'
36
                )
37
            ),
38
            null
39
        );
40
        $represention2 =  $factory->createRepresentation(
41
            $pagerProhecy->reveal(),
42
            new Route(
43
                'users',
44
                array(
45
                    'query' => 'hateoas'
46
                )
47
            ),
48
            null
49
        );
50
        $this->assertEquals(new CollectionRepresentation($results), $represention1->getInline());
51
        $this->assertEquals(new CollectionRepresentation($results), $represention2->getInline());
52
53 View Code Duplication
        foreach(array($represention1, $represention2) as $representation){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
            $this->assertInstanceOf('Hateoas\Representation\PaginatedRepresentation', $representation);
55
            $this->assertSame(1, $representation->getPage());
56
            $this->assertSame(50, $representation->getTotal());
57
            $this->assertSame(20, $representation->getLimit());
58
            $this->assertSame(3, $representation->getPages());
59
            $this->assertSame('limit', $representation->getLimitParameterName());
60
            $this->assertSame('page', $representation->getPageParameterName());
61
            $this->assertSame(
62
                [
63
                    'query' => 'hateoas',
64
                    'page' => 1,
65
                    'limit' => 20
66
                ],
67
                $representation->getParameters()
68
            );
69
        }
70
    }
71
72
    public function testSerialize(){
73
74
        $factory = new KnpPaginatorFactory();
75
76
        $paginator = new Paginator;
77
78
        $paginate = $paginator->paginate(
79
            array(
80
                'mela',
81
                'meli',
82
                'melo'
83
            ), 1, 10
84
        );
85
86
        $collection = $factory->createRepresentation($paginate, new Route('my_route'));
0 ignored issues
show
Compatibility introduced by
$paginate of type object<Knp\Component\Pag...on\PaginationInterface> is not a sub-type of object<Knp\Component\Pag...tion\SlidingPagination>. It seems like you assume a concrete implementation of the interface Knp\Component\Pager\Pagination\PaginationInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
87
88
        $this->assertJsonStringEqualsJsonString(
89
            <<<JSON
90
{
91
    "page": 1,
92
    "limit": 10,
93
    "pages": 1,
94
    "total": 3,
95
    "_links": {
96
        "self": {
97
            "href": "my_route?page=1&limit=10"
98
        },
99
        "first": {
100
            "href": "my_route?page=1&limit=10"
101
        },
102
        "last": {
103
            "href": "my_route?page=1&limit=10"
104
        }
105
    },
106
    "_embedded": {
107
        "items": [
108
            "mela",
109
            "meli",
110
            "melo"
111
        ]
112
    }
113
}
114
JSON
115
        ,
116
            $this->json($this->hateoas->serialize($collection, 'json'))
117
118
        );
119
120
121
        $this->assertXmlStringEqualsXmlString(
122
            <<<XML
123
<?xml version="1.0" encoding="UTF-8"?>
124
<collection page="1" limit="10" pages="1" total="3">
125
  <entry rel="items">
126
    <entry><![CDATA[mela]]></entry>
127
    <entry><![CDATA[meli]]></entry>
128
    <entry><![CDATA[melo]]></entry>
129
  </entry>
130
  <link rel="self" href="my_route?page=1&amp;limit=10"/>
131
  <link rel="first" href="my_route?page=1&amp;limit=10"/>
132
  <link rel="last" href="my_route?page=1&amp;limit=10"/>
133
</collection>
134
135
XML
136
            ,
137
            $this->hateoas->serialize($collection, 'xml')
138
        );
139
    }
140
}
141