@@ -235,56 +235,51 @@ public function testTouchCreatesEmptyFilesFromTraversableObject()
235235 $ this ->assertFileExists ($ basePath .'3 ' );
236236 }
237237
238- public function testRemoveCleansFilesLinksAndDirectoriesIteratively ()
238+ public function testRemoveCleansFilesAndDirectoriesIteratively ()
239239 {
240240 $ basePath = $ this ->workspace .DIRECTORY_SEPARATOR .'directory ' .DIRECTORY_SEPARATOR ;
241241
242242 mkdir ($ basePath );
243243 mkdir ($ basePath .'dir ' );
244244 touch ($ basePath .'file ' );
245- link ($ basePath .'file ' , $ basePath .'link ' );
246245
247246 $ this ->filesystem ->remove ($ basePath );
248247
249248 $ this ->assertTrue (!is_dir ($ basePath ));
250249 }
251250
252- public function testRemoveCleansArrayOfFilesLinksAndDirectories ()
251+ public function testRemoveCleansArrayOfFilesAndDirectories ()
253252 {
254253 $ basePath = $ this ->workspace .DIRECTORY_SEPARATOR ;
255254
256255 mkdir ($ basePath .'dir ' );
257256 touch ($ basePath .'file ' );
258- link ($ basePath .'file ' , $ basePath .'link ' );
259257
260258 $ files = array (
261- $ basePath .'dir ' , $ basePath .'file ' , $ basePath . ' link '
259+ $ basePath .'dir ' , $ basePath .'file '
262260 );
263261
264262 $ this ->filesystem ->remove ($ files );
265263
266264 $ this ->assertTrue (!is_dir ($ basePath .'dir ' ));
267265 $ this ->assertTrue (!is_file ($ basePath .'file ' ));
268- $ this ->assertTrue (!is_link ($ basePath .'link ' ));
269266 }
270267
271- public function testRemoveCleansTraversableObjectOfFilesLinksAndDirectories ()
268+ public function testRemoveCleansTraversableObjectOfFilesAndDirectories ()
272269 {
273270 $ basePath = $ this ->workspace .DIRECTORY_SEPARATOR ;
274271
275272 mkdir ($ basePath .'dir ' );
276273 touch ($ basePath .'file ' );
277- link ($ basePath .'file ' , $ basePath .'link ' );
278274
279275 $ files = new \ArrayObject (array (
280- $ basePath .'dir ' , $ basePath .'file ' , $ basePath . ' link '
276+ $ basePath .'dir ' , $ basePath .'file '
281277 ));
282278
283279 $ this ->filesystem ->remove ($ files );
284280
285281 $ this ->assertTrue (!is_dir ($ basePath .'dir ' ));
286282 $ this ->assertTrue (!is_file ($ basePath .'file ' ));
287- $ this ->assertTrue (!is_link ($ basePath .'link ' ));
288283 }
289284
290285 public function testRemoveIgnoresNonExistingFiles ()
@@ -368,6 +363,53 @@ public function testRenameThrowsExceptionIfTargetAlreadyExists()
368363 $ this ->filesystem ->rename ($ file , $ newPath );
369364 }
370365
366+ public function testSymlink ()
367+ {
368+ $ this ->markAsSkippeIfSymlinkIsMissing ();
369+
370+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'file ' ;
371+ $ link = $ this ->workspace .DIRECTORY_SEPARATOR .'link ' ;
372+
373+ touch ($ file );
374+
375+ $ this ->filesystem ->symlink ($ file , $ link );
376+
377+ $ this ->assertTrue (is_link ($ link ));
378+ $ this ->assertEquals ($ file , readlink ($ link ));
379+ }
380+
381+ public function testSymlinkIsOverwrittenIfPointsToDifferentTarget ()
382+ {
383+ $ this ->markAsSkippeIfSymlinkIsMissing ();
384+
385+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'file ' ;
386+ $ link = $ this ->workspace .DIRECTORY_SEPARATOR .'link ' ;
387+
388+ touch ($ file );
389+ symlink ($ this ->workspace , $ link );
390+
391+ $ this ->filesystem ->symlink ($ file , $ link );
392+
393+ $ this ->assertTrue (is_link ($ link ));
394+ $ this ->assertEquals ($ file , readlink ($ link ));
395+ }
396+
397+ public function testSymlinkIsNotOverwrittenIfAlreadyCreated ()
398+ {
399+ $ this ->markAsSkippeIfSymlinkIsMissing ();
400+
401+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'file ' ;
402+ $ link = $ this ->workspace .DIRECTORY_SEPARATOR .'link ' ;
403+
404+ touch ($ file );
405+ symlink ($ file , $ link );
406+
407+ $ this ->filesystem ->symlink ($ file , $ link );
408+
409+ $ this ->assertTrue (is_link ($ link ));
410+ $ this ->assertEquals ($ file , readlink ($ link ));
411+ }
412+
371413 /**
372414 * Returns file permissions as three digits (i.e. 755)
373415 *
@@ -377,4 +419,11 @@ private function getFilePermisions($filePath)
377419 {
378420 return (int ) substr (sprintf ('%o ' , fileperms ($ filePath )), -3 );
379421 }
422+
423+ private function markAsSkippeIfSymlinkIsMissing ()
424+ {
425+ if (!function_exists ('symlink ' )) {
426+ $ this ->markTestSkipped ('symlink is not supported ' );
427+ }
428+ }
380429}
0 commit comments