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.

PagerfantaFactoryTest::test()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 56
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 56
rs 9.7251
cc 2
eloc 39
nc 2
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\PagerfantaFactory;
8
use Hateoas\Tests\Representation\RepresentationTestCase;
9
use Pagerfanta\Adapter\ArrayAdapter;
10
use Pagerfanta\Pagerfanta;
11
12
class PagerfantaFactoryTest extends RepresentationTestCase
13
{
14
    public function test()
15
    {
16
        $results = array(
17
            'Adrien',
18
            'William',
19
        );
20
21
        $pagerProphecy = $this->prophesize('Pagerfanta\Pagerfanta');
22
        $pagerProphecy->getCurrentPageResults()->willReturn($results);
23
        $pagerProphecy->getCurrentPage()->willReturn(2);
24
        $pagerProphecy->getMaxPerPage()->willReturn(20);
25
        $pagerProphecy->getNbPages()->willReturn(4);
26
        $pagerProphecy->getNbResults()->willReturn(100);
27
28
        $factory = new PagerfantaFactory('p', 'l');
29
        $representation1 = $factory->createRepresentation(
30
            $pagerProphecy->reveal(),
31
            new Route(
32
                'users',
33
                array(
34
                    'query' => 'hateoas',
35
                )
36
            )
37
        );
38
        $representation2 = $factory->createRepresentation(
39
            $pagerProphecy->reveal(),
40
            new Route(
41
                'users',
42
                array(
43
                    'query' => 'hateoas',
44
                )
45
            ),
46
            array()
47
        );
48
49
        $this->assertEquals(new CollectionRepresentation($results), $representation1->getInline());
50
        $this->assertSame([], $representation2->getInline());
51
52
        foreach (array($representation1, $representation2) as $representation) {
53
            $this->assertInstanceOf('Hateoas\Representation\PaginatedRepresentation', $representation);
54
            $this->assertSame(2, $representation->getPage());
55
            $this->assertSame(20, $representation->getLimit());
56
            $this->assertSame(4, $representation->getPages());
57
            $this->assertSame(100, $representation->getTotal());
58
            $this->assertSame(
59
                [
60
                    'query' => 'hateoas',
61
                    'p' => 2,
62
                    'l' => 20,
63
                ],
64
                $representation->getParameters()
65
            );
66
            $this->assertSame('p', $representation->getPageParameterName());
67
            $this->assertSame('l', $representation->getLimitParameterName());
68
        }
69
    }
70
71
    public function testSerialize()
72
    {
73
        $factory    = new PagerfantaFactory();
74
        $pagerfanta = new Pagerfanta(new ArrayAdapter(array(
75
            'bim',
76
            'bam',
77
            'boom'
78
        )));
79
80
        $collection = $factory->createRepresentation($pagerfanta, new Route('my_route'));
81
82
        $this->assertSame(
83
            <<<XML
84
<?xml version="1.0" encoding="UTF-8"?>
85
<collection page="1" limit="10" pages="1" total="3">
86
  <entry rel="items">
87
    <entry><![CDATA[bim]]></entry>
88
    <entry><![CDATA[bam]]></entry>
89
    <entry><![CDATA[boom]]></entry>
90
  </entry>
91
  <link rel="self" href="my_route?page=1&amp;limit=10"/>
92
  <link rel="first" href="my_route?page=1&amp;limit=10"/>
93
  <link rel="last" href="my_route?page=1&amp;limit=10"/>
94
</collection>
95
96
XML
97
            ,
98
            $this->hateoas->serialize($collection, 'xml')
99
        );
100
        $this->assertSame(
101
            <<<JSON
102
{
103
    "page": 1,
104
    "limit": 10,
105
    "pages": 1,
106
    "total": 3,
107
    "_links": {
108
        "self": {
109
            "href": "my_route?page=1&limit=10"
110
        },
111
        "first": {
112
            "href": "my_route?page=1&limit=10"
113
        },
114
        "last": {
115
            "href": "my_route?page=1&limit=10"
116
        }
117
    },
118
    "_embedded": {
119
        "items": [
120
            "bim",
121
            "bam",
122
            "boom"
123
        ]
124
    }
125
}
126
JSON
127
            ,
128
            $this->json($this->hateoas->serialize($collection, 'json'))
129
        );
130
    }
131
132
    public function testGenerateAbsoluteURIs()
133
    {
134
        $factory    = new PagerfantaFactory();
135
        $pagerfanta = new Pagerfanta(new ArrayAdapter(array(
136
            'bim',
137
            'bam',
138
            'boom'
139
        )));
140
141
        $collection = $factory->createRepresentation(
142
            $pagerfanta,
143
            new Route(
144
                '/my_route',
145
                array(),
146
                true
147
            )
148
        );
149
150
        $this->assertSame(
151
            <<<XML
152
<?xml version="1.0" encoding="UTF-8"?>
153
<collection page="1" limit="10" pages="1" total="3">
154
  <entry rel="items">
155
    <entry><![CDATA[bim]]></entry>
156
    <entry><![CDATA[bam]]></entry>
157
    <entry><![CDATA[boom]]></entry>
158
  </entry>
159
  <link rel="self" href="http://example.com/my_route?page=1&amp;limit=10"/>
160
  <link rel="first" href="http://example.com/my_route?page=1&amp;limit=10"/>
161
  <link rel="last" href="http://example.com/my_route?page=1&amp;limit=10"/>
162
</collection>
163
164
XML
165
            ,
166
            $this->hateoas->serialize($collection, 'xml')
167
        );
168
    }
169
}
170