@@ -957,6 +957,97 @@ public function testLinkWithSameTarget()
957957 $ this ->assertEquals (fileinode ($ file ), fileinode ($ link ));
958958 }
959959
960+ public function testReadRelativeLink ()
961+ {
962+ $ this ->markAsSkippedIfSymlinkIsMissing ();
963+
964+ if ('\\' === DIRECTORY_SEPARATOR ) {
965+ $ this ->markTestSkipped ('Relative symbolic links are not supported on Windows ' );
966+ }
967+
968+ $ file = $ this ->workspace .'/file ' ;
969+ $ link1 = $ this ->workspace .'/dir/link ' ;
970+ $ link2 = $ this ->workspace .'/dir/link2 ' ;
971+ touch ($ file );
972+
973+ $ this ->filesystem ->symlink ('../file ' , $ link1 );
974+ $ this ->filesystem ->symlink ('link ' , $ link2 );
975+
976+ $ this ->assertEquals ($ this ->normalize ('../file ' ), $ this ->filesystem ->readlink ($ link1 ));
977+ $ this ->assertEquals ('link ' , $ this ->filesystem ->readlink ($ link2 ));
978+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link1 , true ));
979+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link2 , true ));
980+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ file , true ));
981+ }
982+
983+ public function testReadAbsoluteLink ()
984+ {
985+ $ this ->markAsSkippedIfSymlinkIsMissing ();
986+
987+ $ file = $ this ->normalize ($ this ->workspace .'/file ' );
988+ $ link1 = $ this ->normalize ($ this ->workspace .'/dir/link ' );
989+ $ link2 = $ this ->normalize ($ this ->workspace .'/dir/link2 ' );
990+ touch ($ file );
991+
992+ $ this ->filesystem ->symlink ($ file , $ link1 );
993+ $ this ->filesystem ->symlink ($ link1 , $ link2 );
994+
995+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link1 ));
996+ $ this ->assertEquals ($ link1 , $ this ->filesystem ->readlink ($ link2 ));
997+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link1 , true ));
998+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link2 , true ));
999+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ file , true ));
1000+ }
1001+
1002+ public function testReadBrokenLink ()
1003+ {
1004+ $ this ->markAsSkippedIfSymlinkIsMissing ();
1005+
1006+ if ('\\' === DIRECTORY_SEPARATOR ) {
1007+ $ this ->markTestSkipped ('Windows does not support creating "broken" symlinks ' );
1008+ }
1009+
1010+ $ file = $ this ->workspace .'/file ' ;
1011+ $ link = $ this ->workspace .'/link ' ;
1012+
1013+ $ this ->filesystem ->symlink ($ file , $ link );
1014+
1015+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link ));
1016+ $ this ->assertNull ($ this ->filesystem ->readlink ($ link , true ));
1017+
1018+ touch ($ file );
1019+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link , true ));
1020+ }
1021+
1022+ public function testReadLinkDefaultPathDoesNotExist ()
1023+ {
1024+ $ this ->assertNull ($ this ->filesystem ->readlink ($ this ->normalize ($ this ->workspace .'/invalid ' )));
1025+ }
1026+
1027+ public function testReadLinkDefaultPathNotLink ()
1028+ {
1029+ $ file = $ this ->normalize ($ this ->workspace .'/file ' );
1030+ touch ($ file );
1031+
1032+ $ this ->assertNull ($ this ->filesystem ->readlink ($ file ));
1033+ }
1034+
1035+ public function testReadLinkCanonicalizePath ()
1036+ {
1037+ $ this ->markAsSkippedIfSymlinkIsMissing ();
1038+
1039+ $ file = $ this ->normalize ($ this ->workspace .'/file ' );
1040+ mkdir ($ this ->normalize ($ this ->workspace .'/dir ' ));
1041+ touch ($ file );
1042+
1043+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ this ->normalize ($ this ->workspace .'/dir/../file ' ), true ));
1044+ }
1045+
1046+ public function testReadLinkCanonicalizedPathDoesNotExist ()
1047+ {
1048+ $ this ->assertNull ($ this ->filesystem ->readlink ($ this ->normalize ($ this ->workspace .'invalid ' ), true ));
1049+ }
1050+
9601051 /**
9611052 * @dataProvider providePathsForMakePathRelative
9621053 */
@@ -1321,4 +1412,16 @@ public function testCopyShouldKeepExecutionPermission()
13211412
13221413 $ this ->assertFilePermissions (767 , $ targetFilePath );
13231414 }
1415+
1416+ /**
1417+ * Normalize the given path (transform each blackslash into a real directory separator).
1418+ *
1419+ * @param string $path
1420+ *
1421+ * @return string
1422+ */
1423+ private function normalize ($ path )
1424+ {
1425+ return str_replace ('/ ' , DIRECTORY_SEPARATOR , $ path );
1426+ }
13241427}
0 commit comments