-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathInputParametersTest.php
107 lines (88 loc) · 2.77 KB
/
InputParametersTest.php
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
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\HTTP\Parameters;
use CodeIgniter\Exceptions\InvalidArgumentException;
use CodeIgniter\Test\CIUnitTestCase;
use PHPUnit\Framework\Attributes\Group;
use stdClass;
/**
* @internal
*/
#[Group('Others')]
final class InputParametersTest extends CIUnitTestCase
{
/**
* @var array<string, mixed>
*/
private array $original = [
'title' => '',
'toolbar' => '1',
'path' => 'public/index.php',
'current_time' => 1741522635.661474,
'debug' => true,
'pages' => 15,
'filters' => [
0 => 'name',
1 => 'sum',
],
'sort' => [
'date' => 'ASC',
'age' => 'DESC',
],
];
public function testGetNonScalarValues(): void
{
$parameters = new InputParameters($this->original);
$this->assertNull($parameters->get('undefined_or_null', null));
$this->expectException(InvalidArgumentException::class);
$parameters->get('undefined_throw', new stdClass()); // @phpstan-ignore argument.type
}
public function testAttemptSetNullValues(): void
{
$parameters = new InputParameters($this->original);
$this->expectException(InvalidArgumentException::class);
$parameters->set('nullable', null); // @phpstan-ignore argument.type
}
public function testAttemptSetNonScalarValues(): void
{
$parameters = new InputParameters($this->original);
$this->expectException(InvalidArgumentException::class);
$parameters->set('nullable', new stdClass()); // @phpstan-ignore argument.type
}
public function testUpdateAndSetNewValues(): void
{
/**
* @var array<string, mixed>
*/
$expected = [
'title' => 'CodeIgniter',
'toolbar' => '0',
'path' => '',
'current_time' => 1741522888.661434,
'debug' => false,
'pages' => 10,
'filters' => [
0 => 'sum',
1 => 'name',
],
'sort' => [
'age' => 'ASC',
'date' => 'DESC',
],
'slug' => 'Ben-i-need-help',
];
$parameters = new InputParameters($this->original);
foreach (array_keys($expected) as $key) {
$parameters->set($key, $expected[$key]);
}
$this->assertSame($expected, $parameters->all());
}
}