@@ -77,17 +77,26 @@ public function testFromReflectionClass(): void {
7777 }
7878
7979 public function testWithRealpathRoot (): void {
80- $ this ->assertNamespaceDir (
81- __DIR__ ,
82- __NAMESPACE__ ,
83- $ this
84- ->nsdir (__DIR__ . '/../src ' , __NAMESPACE__ )
85- ->withRealpathRoot (),
86- );
80+ $ c = fn (string $ dir ) => NamespaceDirectory::create ($ dir , 'Acme\Zoo ' );
81+ $ realpath = realpath (__DIR__ ) ?: $ this ->fail ();
82+ $ crooked_path = __DIR__ . '/../src ' ;
83+ $ this ->assertFalse (str_ends_with ($ realpath , '/../src ' ));
84+ $ obj_with_realpath = $ c ($ realpath );
85+ $ this ->assertEquals ($ obj_with_realpath , $ c ($ crooked_path )->withRealpathRoot ());
86+
87+ // A new clone is returned even though values are the same.
88+ // Perhaps this will change in the future.
89+ $ this ->assertEquals ($ obj_with_realpath , $ obj_with_realpath ->withRealpathRoot ());
90+ $ this ->assertNotSame ($ obj_with_realpath , $ obj_with_realpath ->withRealpathRoot ());
91+
92+ // Test effect on the iterator.
93+ $ this ->assertSame ($ realpath , dirname ($ obj_with_realpath ->getIterator ()->key ()));
94+ $ this ->assertSame ($ crooked_path , dirname ($ c ($ crooked_path )->getIterator ()->key ()));
95+
8796 $ this ->callAndAssertException (
8897 \RuntimeException::class,
8998 fn () => $ this
90- ->nsdir (__DIR__ . '/non/existing/path ' , 'Acme\Foo ' )
99+ ->nsdir (__DIR__ . '/non/existing/path ' , 'Acme\Zoo ' )
91100 ->withRealpathRoot (),
92101 );
93102 }
0 commit comments