Repository navigation
Expand file tree
/
Copy pathQueryInputTest.php
More file actions
118 lines (109 loc) · 3.32 KB
/
Copy pathQueryInputTest.php
File metadata and controls
118 lines (109 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
namespace PHPForge\Debug\Tests\Data;
use PHPForge\Debug\Data\QueryInput;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for {@see QueryInput} covering `Prefix[attribute]` group extraction and scalar top-level reads from parsed
* query parameters.
*/
#[Group('data')]
#[Group('filter')]
final class QueryInputTest extends TestCase
{
public function testGroupDropsEmptyNonScalarAndNonStringKeyedEntries(): void
{
$filters = QueryInput::group(
[
'Debug' => [
'statusCode' => '404',
'url' => '',
'nested' => ['x' => '1'],
0 => 'indexed',
'count' => 7,
],
],
'Debug',
);
self::assertSame(
[
'statusCode' => '404',
'count' => '7',
],
$filters,
'Empty strings, arrays, and integer keys must be dropped; numeric values must stringify.',
);
}
public function testGroupReturnsEmptyArrayWhenPrefixIsAbsentOrNotAnArray(): void
{
self::assertSame(
[],
QueryInput::group([], 'Debug'),
'A missing prefix must yield no filters.',
);
self::assertSame(
[],
QueryInput::group(['Debug' => 'scalar'], 'Debug'),
'A scalar under the prefix must yield no filters.',
);
}
public function testMinimumBoundAcceptsFiniteNonNegativeNumbers(): void
{
self::assertSame(
12.5,
QueryInput::minimumBound('12.5'),
'A decimal bound must be returned as a float.',
);
self::assertSame(
0.0,
QueryInput::minimumBound('0'),
'Zero must remain an accepted lower bound.',
);
self::assertSame(
1.0E+3,
QueryInput::minimumBound('1e3'),
'Scientific notation must be accepted.',
);
}
public function testMinimumBoundRejectsUnusableValues(): void
{
self::assertNull(
QueryInput::minimumBound(''),
'Empty input must be rejected.',
);
self::assertNull(
QueryInput::minimumBound('12ms'),
'Non-numeric input must be rejected.',
);
self::assertNull(
QueryInput::minimumBound('-0.5'),
'Negative bounds must be rejected.',
);
self::assertNull(
QueryInput::minimumBound('1e400'),
'Overflowing input must be rejected.',
);
}
public function testScalarReadsTopLevelStringsAndNumbers(): void
{
self::assertSame(
'all',
QueryInput::scalar(['per-page' => 'all'], 'per-page'),
'Strings must pass through.',
);
self::assertSame(
'25',
QueryInput::scalar(['per-page' => 25], 'per-page'),
'Integers must stringify.',
);
self::assertNull(
QueryInput::scalar([], 'per-page'),
"Missing parameters must yield 'null'.",
);
self::assertNull(
QueryInput::scalar(['per-page' => ['25']], 'per-page'),
"Array parameters must yield 'null'.",
);
}
}