12
12
use PHPUnit \Framework \Attributes \Test ;
13
13
use Stringable ;
14
14
15
+ /**
16
+ * @phpstan-import-type DataType from Value
17
+ */
15
18
final class ItemTest extends StructuredFieldTestCase
16
19
{
17
20
/** @var array<string> */
@@ -28,19 +31,46 @@ final class ItemTest extends StructuredFieldTestCase
28
31
];
29
32
30
33
#[Test]
31
- public function it_fails_to_instantiate_a_decimal_too_big (): void
34
+ #[DataProvider('provideInvalidArguments ' )]
35
+ public function it_fails_to_instantiate_an_item (mixed $ value ): void
32
36
{
33
37
$ this ->expectException (SyntaxError::class);
34
38
35
- Item::from (1_000_000_000_000.0 );
39
+ Item::from ($ value );
36
40
}
37
41
38
- #[Test]
39
- public function it_fails_to_instantiate_a_decimal_too_small (): void
42
+ /**
43
+ * @return iterable<string, array{value:mixed}>
44
+ */
45
+ public static function provideInvalidArguments (): iterable
40
46
{
41
- $ this ->expectException (SyntaxError::class);
47
+ yield 'if the decimal is too big ' => [
48
+ 'value ' => 1_000_000_000_000.0 ,
49
+ ];
50
+
51
+ yield 'if the decimal is too small ' => [
52
+ 'value ' => -1_000_000_000_000.0 ,
53
+ ];
54
+
55
+ yield 'if the integer is too big ' => [
56
+ 'value ' => 1_000_000_000_000_000 ,
57
+ ];
42
58
43
- Item::from (-1_000_000_000_000.0 );
59
+ yield 'if the integer is too small ' => [
60
+ 'value ' => -1_000_000_000_000_000 ,
61
+ ];
62
+
63
+ yield 'if the date is too much in the future ' => [
64
+ 'value ' => new DateTime ('@ ' . 1_000_000_000_000_000 ),
65
+ ];
66
+
67
+ yield 'if the date is too much in the past ' => [
68
+ 'value ' => new DateTime ('@ ' .-1_000_000_000_000_000 ),
69
+ ];
70
+
71
+ yield 'if the string contains invalud characters ' => [
72
+ 'value ' => "\0foobar " ,
73
+ ];
44
74
}
45
75
46
76
#[Test]
@@ -91,22 +121,6 @@ public function __toString(): string
91
121
];
92
122
}
93
123
94
- #[Test]
95
- public function it_fails_to_instantiate_a_integer_too_big (): void
96
- {
97
- $ this ->expectException (SyntaxError::class);
98
-
99
- Item::from (1_000_000_000_000_000 );
100
- }
101
-
102
- #[Test]
103
- public function it_fails_to_instantiate_a_integer_too_small (): void
104
- {
105
- $ this ->expectException (SyntaxError::class);
106
-
107
- Item::from (-1_000_000_000_000_000 );
108
- }
109
-
110
124
#[Test]
111
125
public function it_instantiates_a_token (): void
112
126
{
@@ -133,14 +147,6 @@ public function it_fails_to_instantiate_an_invalid_date_format(): void
133
147
Item::fromHttpValue ('@112345.678 ' );
134
148
}
135
149
136
- #[Test]
137
- public function it_fails_to_instantiate_an_out_of_range_date_in_the_future (): void
138
- {
139
- $ this ->expectException (SyntaxError::class);
140
-
141
- Item::from (new DateTime ('@ ' . 1_000_000_000_000_000 ));
142
- }
143
-
144
150
#[Test]
145
151
public function it_fails_to_instantiate_an_out_of_range_timestamp_in_the_future (): void
146
152
{
@@ -149,14 +155,6 @@ public function it_fails_to_instantiate_an_out_of_range_timestamp_in_the_future(
149
155
Item::fromTimestamp (1_000_000_000_000_000 );
150
156
}
151
157
152
- #[Test]
153
- public function it_fails_to_instantiate_an_out_of_range_date_in_the_past (): void
154
- {
155
- $ this ->expectException (SyntaxError::class);
156
-
157
- Item::from (new DateTime ('@ ' .-1_000_000_000_000_000 ));
158
- }
159
-
160
158
#[Test]
161
159
public function it_fails_to_instantiate_an_out_of_range_timestamp_in_the_past (): void
162
160
{
@@ -205,14 +203,6 @@ public function it_instantiates_a_string(): void
205
203
self ::assertSame ('"foobar" ' , Item::from ('foobar ' )->toHttpValue ());
206
204
}
207
205
208
- #[Test]
209
- public function it_fails_to_instantiate_an_invalid_string (): void
210
- {
211
- $ this ->expectException (SyntaxError::class);
212
-
213
- Item::from ("\0foobar " );
214
- }
215
-
216
206
#[Test]
217
207
#[DataProvider('itemTypeProvider ' )]
218
208
public function it_can_tell_the_item_type (Item $ item , Type $ expectedType ): void
0 commit comments