@@ -956,6 +956,85 @@ public function testLinkWithSameTarget()
956
956
$ this ->assertTrue (is_file ($ link ));
957
957
$ this ->assertEquals (fileinode ($ file ), fileinode ($ link ));
958
958
}
959
+ public function testReadRelativeLink ()
960
+ {
961
+ $ this ->markAsSkippedIfSymlinkIsMissing ();
962
+
963
+ if ('\\' === DIRECTORY_SEPARATOR ) {
964
+ $ this ->markTestSkipped ('Relative symbolic links are not supported on Windows ' );
965
+ }
966
+
967
+ $ file = $ this ->normalize ($ this ->workspace .'/file ' );
968
+ $ link1 = $ this ->normalize ($ this ->workspace .'/dir/link ' );
969
+ $ link2 = $ this ->normalize ($ this ->workspace .'/dir/link2 ' );
970
+ touch ($ file );
971
+
972
+ $ this ->filesystem ->symlink ($ this ->normalize ('../file ' ), $ link1 );
973
+ $ this ->filesystem ->symlink ('link ' , $ link2 );
974
+
975
+ $ this ->assertEquals ($ this ->normalize ('../file ' ), $ this ->filesystem ->readlink ($ link1 ));
976
+ $ this ->assertEquals ('link ' , $ this ->filesystem ->readlink ($ link2 ));
977
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link1 , true ));
978
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link2 , true ));
979
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ file , true ));
980
+ }
981
+
982
+ public function testReadBrokenLink ()
983
+ {
984
+ $ this ->markAsSkippedIfSymlinkIsMissing ();
985
+
986
+ if ('\\' === DIRECTORY_SEPARATOR ) {
987
+ $ this ->markTestSkipped ('Windows does not support creating "broken" symlinks ' );
988
+ }
989
+
990
+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'file ' ;
991
+ $ link = $ this ->workspace .DIRECTORY_SEPARATOR .'link ' ;
992
+
993
+ $ this ->filesystem ->symlink ($ file , $ link );
994
+
995
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link ));
996
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ link , true ));
997
+
998
+ touch ($ file );
999
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link , true ));
1000
+ }
1001
+
1002
+ public function testReadAbsoluteLink ()
1003
+ {
1004
+ $ this ->markAsSkippedIfSymlinkIsMissing ();
1005
+
1006
+ $ file = $ this ->normalize ($ this ->workspace .'/file ' );
1007
+ $ link1 = $ this ->normalize ($ this ->workspace .'/dir/link ' );
1008
+ $ link2 = $ this ->normalize ($ this ->workspace .'/dir/link2 ' );
1009
+ touch ($ file );
1010
+
1011
+ $ this ->filesystem ->symlink ($ file , $ link1 );
1012
+ $ this ->filesystem ->symlink ($ link1 , $ link2 );
1013
+
1014
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link1 ));
1015
+ $ this ->assertEquals ($ link1 , $ this ->filesystem ->readlink ($ link2 ));
1016
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link1 , true ));
1017
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link2 , true ));
1018
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ file , true ));
1019
+ }
1020
+
1021
+ public function testReadLinkDefaultPathDoesNotExist ()
1022
+ {
1023
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ this ->normalize ($ this ->workspace .'/invalid ' )));
1024
+ }
1025
+
1026
+ public function testReadLinkDefaultPathNotLink ()
1027
+ {
1028
+ $ file = $ this ->normalize ($ this ->workspace .'/file ' );
1029
+ touch ($ file );
1030
+
1031
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ file ));
1032
+ }
1033
+
1034
+ public function testReadLinkCanonicalizedPathDoesNotExist ()
1035
+ {
1036
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ this ->normalize ($ this ->workspace .'invalid ' ), true ));
1037
+ }
959
1038
960
1039
/**
961
1040
* @dataProvider providePathsForMakePathRelative
@@ -1321,4 +1400,16 @@ public function testCopyShouldKeepExecutionPermission()
1321
1400
1322
1401
$ this ->assertFilePermissions (767 , $ targetFilePath );
1323
1402
}
1403
+
1404
+ /**
1405
+ * Normalize the given path (transform each blackslash into a real directory separator).
1406
+ *
1407
+ * @param string $path
1408
+ *
1409
+ * @return string
1410
+ */
1411
+ private function normalize ($ path )
1412
+ {
1413
+ return str_replace ('/ ' , DIRECTORY_SEPARATOR , $ path );
1414
+ }
1324
1415
}
0 commit comments