These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Hateoas\Tests\Representation; |
||
4 | |||
5 | use Hateoas\Representation\CollectionRepresentation; |
||
6 | use Hateoas\Representation\PaginatedRepresentation; |
||
7 | use Hateoas\Tests\Fixtures\UsersRepresentation; |
||
8 | |||
9 | class PaginatedRepresentationTest extends RepresentationTestCase |
||
10 | { |
||
11 | View Code Duplication | public function testSerialize() |
|
0 ignored issues
–
show
|
|||
12 | { |
||
13 | $collection = new PaginatedRepresentation( |
||
14 | new CollectionRepresentation( |
||
15 | array( |
||
16 | 'Adrien', |
||
17 | 'William', |
||
18 | ), |
||
19 | 'authors', |
||
20 | 'users' |
||
21 | ), |
||
22 | '/authors', |
||
23 | array( |
||
24 | 'query' => 'willdurand/Hateoas', |
||
25 | ), |
||
26 | 3, |
||
27 | 20, |
||
28 | 17, |
||
29 | null, |
||
30 | null, |
||
31 | false, |
||
32 | 100 |
||
33 | ); |
||
34 | |||
35 | $this |
||
0 ignored issues
–
show
The method
string() does not exist on mageekguy\atoum\asserters\string . Did you maybe mean __toString() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise.
Loading history...
|
|||
36 | ->string($this->hateoas->serialize($collection, 'xml')) |
||
37 | ->isEqualTo( |
||
38 | <<<XML |
||
39 | <?xml version="1.0" encoding="UTF-8"?> |
||
40 | <collection page="3" limit="20" pages="17" total="100"> |
||
41 | <users rel="authors"> |
||
42 | <entry><![CDATA[Adrien]]></entry> |
||
43 | <entry><![CDATA[William]]></entry> |
||
44 | </users> |
||
45 | <link rel="self" href="/authors?query=willdurand%2FHateoas&page=3&limit=20"/> |
||
46 | <link rel="first" href="/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
||
47 | <link rel="last" href="/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
||
48 | <link rel="next" href="/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
||
49 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
||
50 | </collection> |
||
51 | |||
52 | XML |
||
53 | ) |
||
54 | ->string($this->halHateoas->serialize($collection, 'xml')) |
||
55 | ->isEqualTo( |
||
56 | <<<XML |
||
57 | <?xml version="1.0" encoding="UTF-8"?> |
||
58 | <collection page="3" limit="20" pages="17" total="100" href="/authors?query=willdurand%2FHateoas&page=3&limit=20"> |
||
59 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
||
60 | <resource rel="authors"><![CDATA[William]]></resource> |
||
61 | <link rel="first" href="/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
||
62 | <link rel="last" href="/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
||
63 | <link rel="next" href="/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
||
64 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
||
65 | </collection> |
||
66 | |||
67 | XML |
||
68 | ) |
||
69 | ->string($this->hateoas->serialize(new UsersRepresentation($collection), 'xml')) |
||
70 | ->isEqualTo( |
||
71 | <<<XML |
||
72 | <?xml version="1.0" encoding="UTF-8"?> |
||
73 | <users page="3" limit="20" pages="17" total="100"> |
||
74 | <users rel="authors"> |
||
75 | <entry><![CDATA[Adrien]]></entry> |
||
76 | <entry><![CDATA[William]]></entry> |
||
77 | </users> |
||
78 | <link rel="self" href="/authors?query=willdurand%2FHateoas&page=3&limit=20"/> |
||
79 | <link rel="first" href="/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
||
80 | <link rel="last" href="/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
||
81 | <link rel="next" href="/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
||
82 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
||
83 | </users> |
||
84 | |||
85 | XML |
||
86 | ) |
||
87 | ->string($this->halHateoas->serialize(new UsersRepresentation($collection), 'xml')) |
||
88 | ->isEqualTo( |
||
89 | <<<XML |
||
90 | <?xml version="1.0" encoding="UTF-8"?> |
||
91 | <users page="3" limit="20" pages="17" total="100" href="/authors?query=willdurand%2FHateoas&page=3&limit=20"> |
||
92 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
||
93 | <resource rel="authors"><![CDATA[William]]></resource> |
||
94 | <link rel="first" href="/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
||
95 | <link rel="last" href="/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
||
96 | <link rel="next" href="/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
||
97 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
||
98 | </users> |
||
99 | |||
100 | XML |
||
101 | ) |
||
102 | ->string($this->halHateoas->serialize($collection, 'json')) |
||
103 | ->isEqualTo( |
||
104 | '{' |
||
105 | .'"page":3,' |
||
106 | .'"limit":20,' |
||
107 | .'"pages":17,' |
||
108 | .'"total":100,' |
||
109 | .'"_links":{' |
||
110 | .'"self":{' |
||
111 | .'"href":"\/authors?query=willdurand%2FHateoas&page=3&limit=20"' |
||
112 | .'},' |
||
113 | .'"first":{' |
||
114 | .'"href":"\/authors?query=willdurand%2FHateoas&page=1&limit=20"' |
||
115 | .'},' |
||
116 | .'"last":{' |
||
117 | .'"href":"\/authors?query=willdurand%2FHateoas&page=17&limit=20"' |
||
118 | .'},' |
||
119 | .'"next":{' |
||
120 | .'"href":"\/authors?query=willdurand%2FHateoas&page=4&limit=20"' |
||
121 | .'},' |
||
122 | .'"previous":{' |
||
123 | .'"href":"\/authors?query=willdurand%2FHateoas&page=2&limit=20"' |
||
124 | .'}' |
||
125 | .'},' |
||
126 | .'"_embedded":{' |
||
127 | .'"authors":[' |
||
128 | .'"Adrien",' |
||
129 | .'"William"' |
||
130 | .']' |
||
131 | .'}' |
||
132 | .'}' |
||
133 | ) |
||
134 | ; |
||
135 | } |
||
136 | |||
137 | View Code Duplication | public function testGenerateAbsoluteURIs() |
|
138 | { |
||
139 | $collection = new PaginatedRepresentation( |
||
140 | new CollectionRepresentation( |
||
141 | array( |
||
142 | 'Adrien', |
||
143 | 'William', |
||
144 | ), |
||
145 | 'authors', |
||
146 | 'users' |
||
147 | ), |
||
148 | '/authors', |
||
149 | array( |
||
150 | 'query' => 'willdurand/Hateoas', |
||
151 | ), |
||
152 | 3, |
||
153 | 20, |
||
154 | 17, |
||
155 | null, |
||
156 | null, |
||
157 | true // force absolute URIs |
||
158 | ); |
||
159 | |||
160 | $this |
||
0 ignored issues
–
show
The method
string() does not exist on mageekguy\atoum\asserters\string . Did you maybe mean __toString() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise.
Loading history...
|
|||
161 | ->string($this->hateoas->serialize($collection, 'xml')) |
||
162 | ->isEqualTo( |
||
163 | <<<XML |
||
164 | <?xml version="1.0" encoding="UTF-8"?> |
||
165 | <collection page="3" limit="20" pages="17"> |
||
166 | <users rel="authors"> |
||
167 | <entry><![CDATA[Adrien]]></entry> |
||
168 | <entry><![CDATA[William]]></entry> |
||
169 | </users> |
||
170 | <link rel="self" href="http://example.com/authors?query=willdurand%2FHateoas&page=3&limit=20"/> |
||
171 | <link rel="first" href="http://example.com/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
||
172 | <link rel="last" href="http://example.com/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
||
173 | <link rel="next" href="http://example.com/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
||
174 | <link rel="previous" href="http://example.com/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
||
175 | </collection> |
||
176 | |||
177 | XML |
||
178 | ) |
||
179 | ->string($this->halHateoas->serialize($collection, 'xml')) |
||
180 | ->isEqualTo( |
||
181 | <<<XML |
||
182 | <?xml version="1.0" encoding="UTF-8"?> |
||
183 | <collection page="3" limit="20" pages="17" href="http://example.com/authors?query=willdurand%2FHateoas&page=3&limit=20"> |
||
184 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
||
185 | <resource rel="authors"><![CDATA[William]]></resource> |
||
186 | <link rel="first" href="http://example.com/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
||
187 | <link rel="last" href="http://example.com/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
||
188 | <link rel="next" href="http://example.com/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
||
189 | <link rel="previous" href="http://example.com/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
||
190 | </collection> |
||
191 | |||
192 | XML |
||
193 | ) |
||
194 | ->string($this->halHateoas->serialize($collection, 'json')) |
||
195 | ->isEqualTo( |
||
196 | '{' |
||
197 | .'"page":3,' |
||
198 | .'"limit":20,' |
||
199 | .'"pages":17,' |
||
200 | .'"_links":{' |
||
201 | .'"self":{' |
||
202 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=3&limit=20"' |
||
203 | .'},' |
||
204 | .'"first":{' |
||
205 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=1&limit=20"' |
||
206 | .'},' |
||
207 | .'"last":{' |
||
208 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=17&limit=20"' |
||
209 | .'},' |
||
210 | .'"next":{' |
||
211 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=4&limit=20"' |
||
212 | .'},' |
||
213 | .'"previous":{' |
||
214 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=2&limit=20"' |
||
215 | .'}' |
||
216 | .'},' |
||
217 | .'"_embedded":{' |
||
218 | .'"authors":[' |
||
219 | .'"Adrien",' |
||
220 | .'"William"' |
||
221 | .']' |
||
222 | .'}' |
||
223 | .'}' |
||
224 | ) |
||
225 | ; |
||
226 | } |
||
227 | } |
||
228 |
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.