22
33declare (strict_types=1 );
44
5+ /**
6+ * This file is part of php-fast-forward/config.
7+ *
8+ * This source file is subject to the license bundled
9+ * with this source code in the file LICENSE.
10+ *
11+ * @link https://github.com/php-fast-forward/config
12+ * @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+ * @license https://opensource.org/licenses/MIT MIT License
14+ */
15+
516namespace FastForward \Config \Tests ;
617
718use FastForward \Config \ArrayConfig ;
8- use FastForward \Config \ConfigInterface ;
919use FastForward \Config \Exception \InvalidArgumentException ;
1020use PHPUnit \Framework \Attributes \CoversClass ;
1121use PHPUnit \Framework \Attributes \Test ;
1222use PHPUnit \Framework \Attributes \UsesClass ;
1323use PHPUnit \Framework \TestCase ;
1424
25+ /**
26+ * @internal
27+ */
1528#[CoversClass(ArrayConfig::class)]
1629#[UsesClass(InvalidArgumentException::class)]
1730final class ArrayConfigTest extends TestCase
1831{
1932 #[Test]
20- public function testGetWillReturnPrimitiveOrNestedConfig ()
33+ public function testGetWillReturnPrimitiveOrNestedConfig (): void
2134 {
22- $ key = uniqid ('key_ ' );
35+ $ key = uniqid ('key_ ' );
2336 $ nestedKey = $ key . '.nested ' ;
24- $ val = uniqid ('val_ ' );
25- $ default = uniqid ('def_ ' );
37+ $ val = uniqid ('val_ ' );
38+ $ default = uniqid ('def_ ' );
2639
2740 $ config = new ArrayConfig ([$ nestedKey => $ val ]);
2841
29- $ this -> assertSame ($ val , $ config ->get ($ nestedKey ));
30- $ this -> assertSame ($ default , $ config ->get (uniqid ('missing_ ' ), $ default ));
42+ self :: assertSame ($ val , $ config ->get ($ nestedKey ));
43+ self :: assertSame ($ default , $ config ->get (uniqid ('missing_ ' ), $ default ));
3144
3245 $ nested = $ config ->get ($ key );
33- $ this -> assertInstanceOf (ArrayConfig::class, $ nested );
34- $ this -> assertSame ([$ key => ['nested ' => $ val ]], $ config ->toArray ());
46+ self :: assertInstanceOf (ArrayConfig::class, $ nested );
47+ self :: assertSame ([$ key => ['nested ' => $ val ]], $ config ->toArray ());
3548 }
3649
3750 #[Test]
38- public function testHasReturnsExpectedResults ()
51+ public function testHasReturnsExpectedResults (): void
3952 {
40- $ key = uniqid ('foo. ' ) . 'bar ' ;
53+ $ key = uniqid ('foo. ' ) . 'bar ' ;
4154 $ config = new ArrayConfig ([$ key => 'value ' ]);
4255
43- $ this -> assertTrue ($ config ->has ($ key ));
44- $ this -> assertFalse ($ config ->has (uniqid ('nope_ ' , true )));
56+ self :: assertTrue ($ config ->has ($ key ));
57+ self :: assertFalse ($ config ->has (uniqid ('nope_ ' , true )));
4558 }
4659
4760 #[Test]
48- public function testSetWithArrayMergesCorrectly ()
61+ public function testSetWithArrayMergesCorrectly (): void
4962 {
5063 $ key1 = uniqid ('x_ ' );
5164 $ key2 = uniqid ('y_ ' );
52- $ v1 = mt_rand (1 , 100 );
53- $ v2 = mt_rand (101 , 200 );
65+ $ v1 = random_int (1 , 100 );
66+ $ v2 = random_int (101 , 200 );
5467
5568 $ config = new ArrayConfig ([$ key1 => $ v1 ]);
5669 $ config ->set ([$ key2 => $ v2 ]);
5770
58- $ this -> assertSame ([$ key1 => $ v1 , $ key2 => $ v2 ], $ config ->toArray ());
71+ self :: assertSame ([$ key1 => $ v1 , $ key2 => $ v2 ], $ config ->toArray ());
5972 }
6073
6174 #[Test]
62- public function testSetWithKeyValuePairs ()
75+ public function testSetWithKeyValuePairs (): void
6376 {
6477 $ key = uniqid ('key_ ' );
6578 $ val = uniqid ('val_ ' );
6679
6780 $ config = new ArrayConfig ();
6881 $ config ->set ($ key , $ val );
6982
70- $ this -> assertSame ([$ key => $ val ], $ config ->toArray ());
83+ self :: assertSame ([$ key => $ val ], $ config ->toArray ());
7184 }
7285
7386 #[Test]
74- public function testSetThrowsExceptionForInvalidKey ()
87+ public function testSetThrowsExceptionForInvalidKey (): void
7588 {
7689 $ this ->expectException (InvalidArgumentException::class);
7790
@@ -80,39 +93,39 @@ public function testSetThrowsExceptionForInvalidKey()
8093 }
8194
8295 #[Test]
83- public function testSetAcceptsAnotherConfigInterface ()
96+ public function testSetAcceptsAnotherConfigInterface (): void
8497 {
85- $ key = uniqid ('shared_ ' );
86- $ value = mt_rand (100 , 999 );
98+ $ key = uniqid ('shared_ ' );
99+ $ value = random_int (100 , 999 );
87100
88101 $ source = new ArrayConfig ([$ key => $ value ]);
89102
90103 $ config = new ArrayConfig ();
91104 $ config ->set ($ source );
92105
93- $ this -> assertSame ([$ key => $ value ], $ config ->toArray ());
106+ self :: assertSame ([$ key => $ value ], $ config ->toArray ());
94107 }
95108
96109 #[Test]
97- public function testGetIteratorYieldsAllKeys ()
110+ public function testGetIteratorYieldsAllKeys (): void
98111 {
99112 $ data = [
100- uniqid ('k1_ ' ) => mt_rand (1 , 10 ),
101- uniqid ('k2_ ' ) => mt_rand (11 , 20 ),
113+ uniqid ('k1_ ' ) => random_int (1 , 10 ),
114+ uniqid ('k2_ ' ) => random_int (11 , 20 ),
102115 ];
103116
104117 $ config = new ArrayConfig ($ data );
105118
106- $ this -> assertSame ($ data , iterator_to_array ($ config ));
119+ self :: assertSame ($ data , iterator_to_array ($ config ));
107120 }
108121
109122 #[Test]
110- public function testDotNotationMergesAssociativeNestedKeys ()
123+ public function testDotNotationMergesAssociativeNestedKeys (): void
111124 {
112125 $ config = new ArrayConfig ([
113126 'db.connection.host ' => 'localhost ' ,
114127 'db.connection.port ' => 3306 ,
115- 'db.options ' => ['charset ' => 'utf8 ' ],
128+ 'db.options ' => ['charset ' => 'utf8 ' ],
116129 ]);
117130
118131 $ expected = [
@@ -127,6 +140,6 @@ public function testDotNotationMergesAssociativeNestedKeys()
127140 ],
128141 ];
129142
130- $ this -> assertSame ($ expected , $ config ->toArray ());
143+ self :: assertSame ($ expected , $ config ->toArray ());
131144 }
132145}
0 commit comments