13
13
class MagicConstantTest extends TestCase
14
14
{
15
15
/** @test */
16
- public function the_constructor_throws_for_an_invalid_value ()
16
+ public function the_constructor_throws_for_an_invalid_value (): void
17
17
{
18
18
/* *** Assertion *** */
19
19
$ this ->expectException (InvalidValueException::class);
@@ -26,7 +26,7 @@ public function the_constructor_throws_for_an_invalid_value()
26
26
}
27
27
28
28
/** @test */
29
- public function the_constructor_throws_for_other_magic_constant_instance ()
29
+ public function the_constructor_throws_for_other_magic_constant_instance (): void
30
30
{
31
31
/* *** Assertion *** */
32
32
$ this ->expectException (InvalidValueException::class);
@@ -39,7 +39,7 @@ public function the_constructor_throws_for_other_magic_constant_instance()
39
39
}
40
40
41
41
/** @test */
42
- public function throws_for_wrong_key ()
42
+ public function throws_for_wrong_key (): void
43
43
{
44
44
/* *** Assertion *** */
45
45
$ this ->expectException (InvalidKeyException::class);
@@ -50,7 +50,7 @@ public function throws_for_wrong_key()
50
50
}
51
51
52
52
/** @test */
53
- public function values_are_case_sensitive ()
53
+ public function values_are_case_sensitive (): void
54
54
{
55
55
/* *** Initialisation *** */
56
56
$ this ->expectException (InvalidValueException::class);
@@ -63,7 +63,7 @@ public function values_are_case_sensitive()
63
63
}
64
64
65
65
/** @test */
66
- public function getValue_throws_for_an_invalid_format ()
66
+ public function getValue_throws_for_an_invalid_format (): void
67
67
{
68
68
/* *** Assertion *** */
69
69
$ this ->expectException (InvalidFormatException::class);
@@ -76,40 +76,33 @@ public function getValue_throws_for_an_invalid_format()
76
76
}
77
77
78
78
/** @test */
79
- public function create_all_possible_values_from_the_constructor ()
79
+ public function create_all_possible_values_from_the_constructor (): void
80
80
{
81
- /* *** Initialisation *** */
82
- $ constants = FakeMagicConstant::toArray ();
83
-
84
81
/* *** Process *** */
85
- foreach ($ constants as $ constant => $ values ) {
86
- foreach ($ values as $ value ) {
87
- $ magicConstant = new FakeMagicConstant ($ value );
88
-
89
- /* *** Assertion *** */
90
- self ::assertSame ($ value , $ magicConstant ->getValue ());
91
- }
92
- }
82
+ self ::assertSame ('foo ' , (new FakeMagicConstant ('foo ' ))->getValue ());
83
+ self ::assertSame (123 , (new FakeMagicConstant (123 ))->getValue ());
84
+ self ::assertSame ('bar ' , (new FakeMagicConstant ('bar ' ))->getValue ());
85
+ self ::assertSame ('A ' , (new FakeMagicConstant ('A ' ))->getValue ());
86
+ self ::assertSame ('B ' , (new FakeMagicConstant ('B ' ))->getValue ());
87
+ self ::assertSame ('C ' , (new FakeMagicConstant ('C ' ))->getValue ());
88
+ self ::assertSame ('value A ' , (new FakeMagicConstant ('value A ' ))->getValue ());
89
+ self ::assertSame ('value B ' , (new FakeMagicConstant ('value B ' ))->getValue ());
90
+ self ::assertSame ('value C ' , (new FakeMagicConstant ('value C ' ))->getValue ());
93
91
}
94
92
95
93
/** @test */
96
- public function create_all_possible_values_from_the_static_method ()
94
+ public function create_all_possible_values_from_the_static_method (): void
97
95
{
98
- /* *** Initialisation *** */
99
- $ constants = FakeMagicConstant::toArray ();
100
-
101
96
/* *** Process *** */
102
- foreach ($ constants as $ constant => $ values ) {
103
- /** @var MagicConstant $magicConstant */
104
- $ magicConstant = FakeMagicConstant::$ constant ();
105
-
106
- /* *** Assertion *** */
107
- self ::assertSame (reset ($ values ), $ magicConstant ->getValue ());
108
- }
97
+ self ::assertSame ('foo ' , FakeMagicConstant::TYPE_STRING ()->getValue ());
98
+ self ::assertSame (123 , FakeMagicConstant::TYPE_INTEGER ()->getValue ());
99
+ self ::assertSame ('bar ' , FakeMagicConstant::TYPE_ARRAY_SINGLE ()->getValue ());
100
+ self ::assertSame ('A ' , FakeMagicConstant::TYPE_ARRAY_MULTIPLE ()->getValue ());
101
+ self ::assertSame ('value A ' , FakeMagicConstant::TYPE_ARRAY_FORMATS ()->getValue ());
109
102
}
110
103
111
104
/** @test */
112
- public function create_instance_from_another_instance ()
105
+ public function create_instance_from_another_instance (): void
113
106
{
114
107
/* *** Initialisation *** */
115
108
$ constants = FakeMagicConstant::values ();
@@ -128,7 +121,7 @@ public function create_instance_from_another_instance()
128
121
* @dataProvider fakeMagicConstantDataProvider
129
122
* @param FakeMagicConstant $magicConstant
130
123
*/
131
- public function getValue_returns_the_correct_value (FakeMagicConstant $ magicConstant )
124
+ public function getValue_returns_the_correct_value (FakeMagicConstant $ magicConstant ): void
132
125
{
133
126
/* *** Process *** */
134
127
$ actualMagicConstant = new FakeMagicConstant ($ magicConstant ->getValue ());
@@ -145,7 +138,7 @@ public function getValue_returns_the_correct_value(FakeMagicConstant $magicConst
145
138
* @param mixed $expectedValue
146
139
* @param string|int $format
147
140
*/
148
- public function getValue_returns_the_correct_value_depending_on_the_format (FakeMagicConstant $ magicConstant , $ key , $ expectedValue , $ format )
141
+ public function getValue_returns_the_correct_value_depending_on_the_format (FakeMagicConstant $ magicConstant , $ key , $ expectedValue , $ format ): void
149
142
{
150
143
/* *** Process *** */
151
144
$ actualMagicConstant = new FakeMagicConstant ($ magicConstant ->getValue ());
@@ -161,7 +154,7 @@ public function getValue_returns_the_correct_value_depending_on_the_format(FakeM
161
154
* @param FakeMagicConstant $magicConstant
162
155
* @param string $expectedKey
163
156
*/
164
- public function getKey_returns_the_correct_value (FakeMagicConstant $ magicConstant , string $ expectedKey )
157
+ public function getKey_returns_the_correct_value (FakeMagicConstant $ magicConstant , string $ expectedKey ): void
165
158
{
166
159
/* *** Process *** */
167
160
$ actualMagicConstant = new FakeMagicConstant ($ magicConstant ->getValue ());
@@ -177,7 +170,7 @@ public function getKey_returns_the_correct_value(FakeMagicConstant $magicConstan
177
170
* @param string|int $key
178
171
* @param mixed $expectedValue
179
172
*/
180
- public function toString_returns_the_correct_value (FakeMagicConstant $ magicConstant , $ key , $ expectedValue )
173
+ public function toString_returns_the_correct_value (FakeMagicConstant $ magicConstant , $ key , $ expectedValue ): void
181
174
{
182
175
/* *** Process *** */
183
176
$ actualValue = (string )$ magicConstant ;
@@ -187,7 +180,7 @@ public function toString_returns_the_correct_value(FakeMagicConstant $magicConst
187
180
}
188
181
189
182
/** @test */
190
- public function keys_returns_the_list_of_possible_keys ()
183
+ public function keys_returns_the_list_of_possible_keys (): void
191
184
{
192
185
/* *** Initialisation *** */
193
186
$ expectedConstants = [
@@ -206,7 +199,7 @@ public function keys_returns_the_list_of_possible_keys()
206
199
}
207
200
208
201
/** @test */
209
- public function values_returns_an_array_of_possible_values ()
202
+ public function values_returns_an_array_of_possible_values (): void
210
203
{
211
204
/* *** Initialisation *** */
212
205
$ extectedValues = [
@@ -224,40 +217,13 @@ public function values_returns_an_array_of_possible_values()
224
217
self ::assertEquals ($ extectedValues , $ actualValues );
225
218
}
226
219
227
- /**
228
- * This test must be run in a separate process to avoid the memoization of values.
229
- * @runInSeparateProcess
230
- * @test
231
- */
232
- public function toArray_returns_an_associative_array_of_constants_and_their_values ()
233
- {
234
- /* *** Initialisation *** */
235
- $ expectedValues = [
236
- 'TYPE_STRING ' => ['foo ' ],
237
- 'TYPE_INTEGER ' => [123 ],
238
- 'TYPE_ARRAY_SINGLE ' => ['bar ' ],
239
- 'TYPE_ARRAY_MULTIPLE ' => ['A ' , 'B ' , 'C ' ],
240
- 'TYPE_ARRAY_FORMATS ' => [
241
- FakeMagicConstant::FORMAT_A => 'value A ' ,
242
- FakeMagicConstant::FORMAT_B => 'value B ' ,
243
- FakeMagicConstant::FORMAT_C => 'value C ' ,
244
- ],
245
- ];
246
-
247
- /* *** Process *** */
248
- $ actualValues = FakeMagicConstant::toArray ();
249
-
250
- /* *** Assertion *** */
251
- self ::assertSame ($ expectedValues , $ actualValues );
252
- }
253
-
254
220
/**
255
221
* @test
256
222
* @dataProvider isValidValueDataProvider
257
223
* @param mixed $value
258
224
* @param $isValid
259
225
*/
260
- public function isValidValue_checks_if_a_value_is_valid ($ value , bool $ isValid )
226
+ public function isValidValue_checks_if_a_value_is_valid ($ value , bool $ isValid ): void
261
227
{
262
228
/* *** Process *** */
263
229
$ actualIsValid = FakeMagicConstant::isValidValue ($ value );
@@ -291,7 +257,7 @@ public function isValidValueDataProvider(): array
291
257
* @param mixed $key
292
258
* @param $isValid
293
259
*/
294
- public function isValidKey_checks_if_a_key_is_valid ($ key , bool $ isValid )
260
+ public function isValidKey_checks_if_a_key_is_valid ($ key , bool $ isValid ): void
295
261
{
296
262
/* *** Process *** */
297
263
$ actualIsValid = FakeMagicConstant::isValidKey ($ key );
@@ -317,48 +283,14 @@ public function isValidKeyDataProvider(): array
317
283
];
318
284
}
319
285
320
- /**
321
- * @test
322
- * @dataProvider searchDataProvider
323
- * @param mixed $value
324
- * @param mixed $expectedKey
325
- */
326
- public function search_finds_the_correct_key ($ value , $ expectedKey )
327
- {
328
- /* *** Process *** */
329
- $ actualKey = FakeMagicConstant::search ($ value );
330
-
331
- /* *** Assertion *** */
332
- self ::assertSame ($ expectedKey , $ actualKey );
333
- }
334
-
335
- /**
336
- * @return array
337
- */
338
- public function searchDataProvider (): array
339
- {
340
- return [
341
- // Valid
342
- ['foo ' , 'TYPE_STRING ' ],
343
- [123 , 'TYPE_INTEGER ' ],
344
- ['bar ' , 'TYPE_ARRAY_SINGLE ' ],
345
- ['A ' , 'TYPE_ARRAY_MULTIPLE ' ],
346
- ['B ' , 'TYPE_ARRAY_MULTIPLE ' ],
347
- ['C ' , 'TYPE_ARRAY_MULTIPLE ' ],
348
-
349
- // Invalid
350
- ['invalid ' , false ],
351
- ];
352
- }
353
-
354
286
/**
355
287
* @test
356
288
* @dataProvider equalsDataProvider
357
289
* @param MagicConstant $magicConstantA
358
290
* @param mixed $magicConstantB
359
291
* @param bool $expectedResult
360
292
*/
361
- public function equals_compares_values (MagicConstant $ magicConstantA , $ magicConstantB , bool $ expectedResult )
293
+ public function equals_compares_values (MagicConstant $ magicConstantA , $ magicConstantB , bool $ expectedResult ): void
362
294
{
363
295
/* *** Process *** */
364
296
$ actualResult = $ magicConstantA ->equals ($ magicConstantB );
@@ -400,7 +332,7 @@ public function equalsDataProvider(): array
400
332
* @param array $values
401
333
* @param bool $expectedResult
402
334
*/
403
- public function in_returns_true_if_at_least_one_value_is_correct (MagicConstant $ magicConstant , array $ values , bool $ expectedResult )
335
+ public function in_returns_true_if_at_least_one_value_is_correct (MagicConstant $ magicConstant , array $ values , bool $ expectedResult ): void
404
336
{
405
337
self ::assertSame ($ expectedResult , $ magicConstant ->in ($ values ));
406
338
self ::assertSame ($ expectedResult , $ magicConstant ->in (array_reverse ($ values )));
@@ -447,7 +379,7 @@ public function fakeMagicConstantDataProvider(): array
447
379
* @param MagicConstant $magicConstant
448
380
* @param array $expectedValues
449
381
*/
450
- public function getAllFormats_returns_instances_in_all_possible_formats (MagicConstant $ magicConstant , array $ expectedValues )
382
+ public function getAllFormats_returns_instances_in_all_possible_formats (MagicConstant $ magicConstant , array $ expectedValues ): void
451
383
{
452
384
/* *** Process *** */
453
385
$ actualValues = $ magicConstant ->getAllFormats ();
@@ -486,7 +418,7 @@ public function allFormatsDataProvider(): array
486
418
}
487
419
488
420
/** @test */
489
- public function get_new_instance_in_specific_format ()
421
+ public function get_new_instance_in_specific_format (): void
490
422
{
491
423
/* *** Initialisation *** */
492
424
$ base = FakeMagicConstant::TYPE_ARRAY_FORMATS ();
@@ -502,7 +434,7 @@ public function get_new_instance_in_specific_format()
502
434
self ::assertSame ('value C ' , $ instanceFormatC ->getValue ());
503
435
}
504
436
505
- public function test_normalize_resets_an_instance_to_the_first_format ()
437
+ public function test_normalize_resets_an_instance_to_the_first_format (): void
506
438
{
507
439
/* *** Initialisation *** */
508
440
$ withoutFormats = new FakeMagicConstant ('B ' );
@@ -551,7 +483,7 @@ public function allValuesDataProvider(): array
551
483
* @param MagicConstant $magicConstant
552
484
* @param array $expectedValues
553
485
*/
554
- public function test_return_values_in_all_formats (MagicConstant $ magicConstant , array $ expectedValues )
486
+ public function test_return_values_in_all_formats (MagicConstant $ magicConstant , array $ expectedValues ): void
555
487
{
556
488
/* *** Process *** */
557
489
$ actualValues = $ magicConstant ->getAllValues ();
@@ -560,12 +492,27 @@ public function test_return_values_in_all_formats(MagicConstant $magicConstant,
560
492
self ::assertSame ($ expectedValues , $ actualValues );
561
493
}
562
494
563
- public function test_has_custom_value_setter ()
495
+ public function test_has_custom_value_setter (): void
564
496
{
565
497
$ magicConstant1 = new CustomSetValueMagicConstant ('FOO ' );
566
498
$ magicConstant2 = new CustomSetValueMagicConstant ('foo ' );
567
499
568
500
self ::assertSame ('foo ' , $ magicConstant1 ->getValue ());
569
501
self ::assertSame ('foo ' , $ magicConstant2 ->getValue ());
570
502
}
503
+
504
+ public function test_getFormat_returns_the_instance_format (): void
505
+ {
506
+ self ::assertEquals (0 , (new FakeMagicConstant ('foo ' ))->getFormat ());
507
+ self ::assertEquals (0 , (new FakeMagicConstant (123 ))->getFormat ());
508
+ self ::assertEquals (0 , (new FakeMagicConstant ('bar ' ))->getFormat ());
509
+
510
+ self ::assertEquals (0 , (new FakeMagicConstant ('A ' ))->getFormat ());
511
+ self ::assertEquals (1 , (new FakeMagicConstant ('B ' ))->getFormat ());
512
+ self ::assertEquals (2 , (new FakeMagicConstant ('C ' ))->getFormat ());
513
+
514
+ self ::assertEquals ('format A ' , (new FakeMagicConstant ('value A ' ))->getFormat ());
515
+ self ::assertEquals ('format B ' , (new FakeMagicConstant ('value B ' ))->getFormat ());
516
+ self ::assertEquals ('format C ' , (new FakeMagicConstant ('value C ' ))->getFormat ());
517
+ }
571
518
}
0 commit comments