Skip to content

Commit eccdd7b

Browse files
ppaulisweierophinney
authored andcommitted
#75 added and completed Units to test page_size parameter more thoroughly
Signed-off-by: Pascal Paulis <[email protected]>
1 parent a799807 commit eccdd7b

File tree

1 file changed

+109
-75
lines changed

1 file changed

+109
-75
lines changed

test/InputFilter/RestService/PatchInputFilterTest.php

Lines changed: 109 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -24,82 +24,18 @@ public function getInputFilter(): PatchInputFilter
2424
]);
2525
}
2626

27-
/** @psalm-return array<string, array{0: array<string, mixed>}> */
27+
/**
28+
* @psalm-return array<string, array{
29+
* string|integer
30+
* }>
31+
*/
2832
public function dataProviderIsValidTrue(): array
2933
{
3034
return [
31-
'all-inputs-present' => [
32-
[
33-
'accept_whitelist' => [
34-
0 => 'application/vnd.foo_bar.v1+json',
35-
1 => 'application/hal+json',
36-
2 => 'application/json',
37-
],
38-
'collection_class' => Paginator::class,
39-
'collection_http_methods' => [
40-
0 => 'GET',
41-
1 => 'POST',
42-
],
43-
'collection_name' => 'foo_bar',
44-
'collection_query_whitelist' => [],
45-
'content_type_whitelist' => [
46-
0 => 'application/vnd.foo_bar.v1+json',
47-
1 => 'application/json',
48-
],
49-
'entity_class' => 'StdClass',
50-
'entity_http_methods' => [
51-
0 => 'GET',
52-
1 => 'PATCH',
53-
2 => 'PUT',
54-
3 => 'DELETE',
55-
],
56-
'entity_identifier_name' => 'id',
57-
'hydrator_name' => ArraySerializableHydrator::class,
58-
'page_size' => "25",
59-
'page_size_param' => null,
60-
'resource_class' => 'Foo_Bar\\V1\\Rest\\Baz_Bat\\Baz_BatResource',
61-
'route_identifier_name' => 'foo_bar_id',
62-
'route_match' => '/foo_bar[/:foo_bar_id]',
63-
'selector' => 'HalJson',
64-
'service_name' => 'Baz_Bat',
65-
],
66-
],
67-
'page_size-negative' => [
68-
[
69-
'accept_whitelist' => [
70-
0 => 'application/vnd.foo_bar.v1+json',
71-
1 => 'application/hal+json',
72-
2 => 'application/json',
73-
],
74-
'collection_class' => Paginator::class,
75-
'collection_http_methods' => [
76-
0 => 'GET',
77-
1 => 'POST',
78-
],
79-
'collection_name' => 'foo_bar',
80-
'collection_query_whitelist' => [],
81-
'content_type_whitelist' => [
82-
0 => 'application/vnd.foo_bar.v1+json',
83-
1 => 'application/json',
84-
],
85-
'entity_class' => 'StdClass',
86-
'entity_http_methods' => [
87-
0 => 'GET',
88-
1 => 'PATCH',
89-
2 => 'PUT',
90-
3 => 'DELETE',
91-
],
92-
'entity_identifier_name' => 'id',
93-
'hydrator_name' => ArraySerializableHydrator::class,
94-
'page_size' => -1,
95-
'page_size_param' => null,
96-
'resource_class' => 'Foo_Bar\\V1\\Rest\\Baz_Bat\\Baz_BatResource',
97-
'route_identifier_name' => 'foo_bar_id',
98-
'route_match' => '/foo_bar[/:foo_bar_id]',
99-
'selector' => 'HalJson',
100-
'service_name' => 'Baz_Bat',
101-
],
102-
],
35+
'page_size-string' => ['25'],
36+
'page_size-string-negative' => ['-1'],
37+
'page_size-integer' => [1],
38+
'page_size-integer-negative' => [-1]
10339
];
10440
}
10541

@@ -198,10 +134,46 @@ public function dataProviderIsValidFalse(): array
198134

199135
/**
200136
* @dataProvider dataProviderIsValidTrue
201-
* @param array<string, mixed> $data
137+
* @param mixed $pageSize
202138
*/
203-
public function testIsValidTrue(array $data): void
139+
public function testIsValidTrue($pageSize): void
204140
{
141+
$data =
142+
[
143+
'accept_whitelist' => [
144+
0 => 'application/vnd.foo_bar.v1+json',
145+
1 => 'application/hal+json',
146+
2 => 'application/json',
147+
],
148+
'collection_class' => Paginator::class,
149+
'collection_http_methods' => [
150+
0 => 'GET',
151+
1 => 'POST',
152+
],
153+
'collection_name' => 'foo_bar',
154+
'collection_query_whitelist' => [],
155+
'content_type_whitelist' => [
156+
0 => 'application/vnd.foo_bar.v1+json',
157+
1 => 'application/json',
158+
],
159+
'entity_class' => 'StdClass',
160+
'entity_http_methods' => [
161+
0 => 'GET',
162+
1 => 'PATCH',
163+
2 => 'PUT',
164+
3 => 'DELETE',
165+
],
166+
'entity_identifier_name' => 'id',
167+
'hydrator_name' => ArraySerializableHydrator::class,
168+
'page_size' => $pageSize,
169+
'page_size_param' => null,
170+
'resource_class' => 'Foo_Bar\\V1\\Rest\\Baz_Bat\\Baz_BatResource',
171+
'route_identifier_name' => 'foo_bar_id',
172+
'route_match' => '/foo_bar[/:foo_bar_id]',
173+
'selector' => 'HalJson',
174+
'service_name' => 'Baz_Bat',
175+
];
176+
205177
$filter = $this->getInputFilter();
206178
$filter->setData($data);
207179
self::assertTrue($filter->isValid(), var_export($filter->getMessages(), true));
@@ -224,4 +196,66 @@ public function testIsValidFalse(array $data, array $expectedInvalidKeys): void
224196
sort($testKeys);
225197
self::assertEquals($expectedInvalidKeys, $testKeys);
226198
}
199+
200+
/**
201+
* @psalm-return array<string, array{
202+
* string|integer|float
203+
* }>
204+
*/
205+
public function dataProviderInvalidPageSizes(): array
206+
{
207+
return [
208+
'page_size-string-float' => ['25.5'],
209+
'page_size-string-wrong-negative' => ['-2'],
210+
'page_size-float' => [25.5],
211+
'page_size-integer-wrong-negative' => [-2],
212+
];
213+
}
214+
215+
/**
216+
* @dataProvider dataProviderInvalidPageSizes
217+
* @param mixed $pageSize
218+
*/
219+
public function testInvalidPageSizes($pageSize): void
220+
{
221+
$data =
222+
[
223+
'accept_whitelist' => [
224+
0 => 'application/vnd.foo_bar.v1+json',
225+
1 => 'application/hal+json',
226+
2 => 'application/json',
227+
],
228+
'collection_class' => Paginator::class,
229+
'collection_http_methods' => [
230+
0 => 'GET',
231+
1 => 'POST',
232+
],
233+
'collection_name' => 'foo_bar',
234+
'collection_query_whitelist' => [],
235+
'content_type_whitelist' => [
236+
0 => 'application/vnd.foo_bar.v1+json',
237+
1 => 'application/json',
238+
],
239+
'entity_class' => 'StdClass',
240+
'entity_http_methods' => [
241+
0 => 'GET',
242+
1 => 'PATCH',
243+
2 => 'PUT',
244+
3 => 'DELETE',
245+
],
246+
'entity_identifier_name' => 'id',
247+
'hydrator_name' => ArraySerializableHydrator::class,
248+
'page_size' => $pageSize,
249+
'page_size_param' => null,
250+
'resource_class' => 'Foo_Bar\\V1\\Rest\\Baz_Bat\\Baz_BatResource',
251+
'route_identifier_name' => 'foo_bar_id',
252+
'route_match' => '/foo_bar[/:foo_bar_id]',
253+
'selector' => 'HalJson',
254+
'service_name' => 'Baz_Bat',
255+
];
256+
257+
$filter = $this->getInputFilter();
258+
$filter->setData($data);
259+
self::assertFalse($filter->isValid(), var_export($filter->getMessages(), true));
260+
}
227261
}

0 commit comments

Comments
 (0)