@@ -957,14 +957,84 @@ public function testLinkWithSameTarget()
957
957
$ this ->assertEquals (fileinode ($ file ), fileinode ($ link ));
958
958
}
959
959
960
- /**
961
- * @dataProvider providePathsForMakePathRelative
962
- */
963
- public function testMakePathRelative ($ endPath , $ startPath , $ expectedPath )
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 ->normalize ($ this ->workspace .'/file ' );
969
+ $ link1 = $ this ->normalize ($ this ->workspace .'/dir/link ' );
970
+ $ link2 = $ this ->normalize ($ this ->workspace .'/dir/link2 ' );
971
+ touch ($ file );
972
+
973
+ $ this ->filesystem ->symlink ($ this ->normalize ('../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 testReadBrokenLink ()
984
+ {
985
+ $ this ->markAsSkippedIfSymlinkIsMissing ();
986
+
987
+ if ('\\' === DIRECTORY_SEPARATOR ) {
988
+ $ this ->markTestSkipped ('Windows does not support creating "broken" symlinks ' );
989
+ }
990
+
991
+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'file ' ;
992
+ $ link = $ this ->workspace .DIRECTORY_SEPARATOR .'link ' ;
993
+
994
+ $ this ->filesystem ->symlink ($ file , $ link );
995
+
996
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link ));
997
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ link , true ));
998
+
999
+ touch ($ file );
1000
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link , true ));
1001
+ }
1002
+
1003
+ public function testReadAbsoluteLink ()
964
1004
{
965
- $ path = $ this ->filesystem ->makePathRelative ($ endPath , $ startPath );
1005
+ $ this ->markAsSkippedIfSymlinkIsMissing ();
1006
+
1007
+ $ file = $ this ->normalize ($ this ->workspace .'/file ' );
1008
+ $ link1 = $ this ->normalize ($ this ->workspace .'/dir/link ' );
1009
+ $ link2 = $ this ->normalize ($ this ->workspace .'/dir/link2 ' );
1010
+ touch ($ file );
966
1011
967
- $ this ->assertEquals ($ expectedPath , $ path );
1012
+ $ this ->filesystem ->symlink ($ file , $ link1 );
1013
+ $ this ->filesystem ->symlink ($ link1 , $ link2 );
1014
+
1015
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link1 ));
1016
+ $ this ->assertEquals ($ link1 , $ this ->filesystem ->readlink ($ link2 ));
1017
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link1 , true ));
1018
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ link2 , true ));
1019
+ $ this ->assertEquals ($ file , $ this ->filesystem ->readlink ($ file , 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 testReadLinkCanonicalizedPathDoesNotExist ()
1036
+ {
1037
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ this ->normalize ($ this ->workspace .'invalid ' ), true ));
968
1038
}
969
1039
970
1040
/**
@@ -1321,4 +1391,16 @@ public function testCopyShouldKeepExecutionPermission()
1321
1391
1322
1392
$ this ->assertFilePermissions (767 , $ targetFilePath );
1323
1393
}
1394
+
1395
+ /**
1396
+ * Normalize the given path (transform each blackslash into a real directory separator).
1397
+ *
1398
+ * @param string $path
1399
+ *
1400
+ * @return string
1401
+ */
1402
+ private function normalize ($ path )
1403
+ {
1404
+ return str_replace ('/ ' , DIRECTORY_SEPARATOR , $ path );
1405
+ }
1324
1406
}
0 commit comments