@@ -11,7 +11,7 @@ class ConfigTest extends TestCase
1111{
1212 public function test_should_load_defaults_from_other_instance ()
1313 {
14- $ config = new Config ('' , new MockOtherConfigInstance );
14+ $ config = new Config ('' , new TestOtherConfInstanceClass );
1515 $ this ->assertSame ([1 , 2 , 3 ], $ config ->list );
1616 }
1717
@@ -52,7 +52,7 @@ public function test_should_load_options_from_object_instance()
5252 $ config = new Config ;
5353 $ this ->assertNull ($ config ->foo );
5454
55- $ config ->fromObject (new MockOtherConfigInstance );
55+ $ config ->fromObject (new TestOtherConfInstanceClass );
5656 $ this ->assertSame ('bar ' , $ config ->foo );
5757 }
5858
@@ -61,7 +61,7 @@ public function test_should_load_options_from_object_fqn()
6161 $ config = new Config ;
6262 $ this ->assertNull ($ config ->foo );
6363
64- $ config ->fromObject (MockOtherConfigInstance ::class);
64+ $ config ->fromObject (TestOtherConfInstanceClass ::class);
6565 $ this ->assertSame ('bar ' , $ config ->foo );
6666 }
6767
@@ -241,17 +241,41 @@ public function test_ini_sections_parsing()
241241 $ this ->assertSame (include_once __DIR__ . '/fixtures/config-sections.php ' , $ config ->toArray ());
242242 }
243243
244+ public function test_should_set_root_on_empty_constructor_argument ()
245+ {
246+ $ config = new Config ;
247+ $ this ->assertNotEmpty ($ config ->root );
248+ }
249+
250+ public function test_shoud_set_root_from_empty_object_root ()
251+ {
252+ $ initial = new TestRootFromThisClass ;
253+ $ config = new Config (__DIR__ );
254+ $ config ->fromObject ($ initial );
255+
256+ $ this ->assertSame ($ config ->root , $ initial ->root );
257+ $ this ->assertSame ('/tmp ' , $ config ->root );
258+ }
259+
244260 protected function tearDown (): void
245261 {
246262 env ('' , null , []);
247263 }
248264}
249265
250- class MockOtherConfigInstance extends Config
266+ class TestOtherConfInstanceClass extends Config
251267{
252268 public function __construct ()
253269 {
254270 parent ::__construct ();
255271 $ this ->fromPhpFile (__DIR__ . '/fixtures/nested-array.php ' );
256272 }
257273}
274+
275+ class TestRootFromThisClass extends Config
276+ {
277+ public function __construct ()
278+ {
279+ parent ::__construct ('/tmp ' );
280+ }
281+ }
0 commit comments