@@ -957,14 +957,64 @@ 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 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 testReadLinkDefaultPathDoesNotExist ()
964
1003
{
965
- $ path = $ this ->filesystem ->makePathRelative ($ endPath , $ startPath );
1004
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ this ->normalize ($ this ->workspace .'/invalid ' )));
1005
+ }
1006
+
1007
+ public function testReadLinkDefaultPathNotLink ()
1008
+ {
1009
+ $ file = $ this ->normalize ($ this ->workspace .'/file ' );
1010
+ touch ($ file );
966
1011
967
- $ this ->assertEquals ($ expectedPath , $ path );
1012
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ file ));
1013
+ }
1014
+
1015
+ public function testReadLinkCanonicalizedPathDoesNotExist ()
1016
+ {
1017
+ $ this ->assertNull ($ this ->filesystem ->readlink ($ this ->normalize ($ this ->workspace .'invalid ' ), true ));
968
1018
}
969
1019
970
1020
/**
@@ -1321,4 +1371,16 @@ public function testCopyShouldKeepExecutionPermission()
1321
1371
1322
1372
$ this ->assertFilePermissions (767 , $ targetFilePath );
1323
1373
}
1374
+
1375
+ /**
1376
+ * Normalize the given path (transform each blackslash into a real directory separator).
1377
+ *
1378
+ * @param string $path
1379
+ *
1380
+ * @return string
1381
+ */
1382
+ private function normalize ($ path )
1383
+ {
1384
+ return str_replace ('/ ' , DIRECTORY_SEPARATOR , $ path );
1385
+ }
1324
1386
}
0 commit comments