@@ -235,56 +235,51 @@ public function testTouchCreatesEmptyFilesFromTraversableObject()
235
235
$ this ->assertFileExists ($ basePath .'3 ' );
236
236
}
237
237
238
- public function testRemoveCleansFilesLinksAndDirectoriesIteratively ()
238
+ public function testRemoveCleansFilesAndDirectoriesIteratively ()
239
239
{
240
240
$ basePath = $ this ->workspace .DIRECTORY_SEPARATOR .'directory ' .DIRECTORY_SEPARATOR ;
241
241
242
242
mkdir ($ basePath );
243
243
mkdir ($ basePath .'dir ' );
244
244
touch ($ basePath .'file ' );
245
- link ($ basePath .'file ' , $ basePath .'link ' );
246
245
247
246
$ this ->filesystem ->remove ($ basePath );
248
247
249
248
$ this ->assertTrue (!is_dir ($ basePath ));
250
249
}
251
250
252
- public function testRemoveCleansArrayOfFilesLinksAndDirectories ()
251
+ public function testRemoveCleansArrayOfFilesAndDirectories ()
253
252
{
254
253
$ basePath = $ this ->workspace .DIRECTORY_SEPARATOR ;
255
254
256
255
mkdir ($ basePath .'dir ' );
257
256
touch ($ basePath .'file ' );
258
- link ($ basePath .'file ' , $ basePath .'link ' );
259
257
260
258
$ files = array (
261
- $ basePath .'dir ' , $ basePath .'file ' , $ basePath . ' link '
259
+ $ basePath .'dir ' , $ basePath .'file '
262
260
);
263
261
264
262
$ this ->filesystem ->remove ($ files );
265
263
266
264
$ this ->assertTrue (!is_dir ($ basePath .'dir ' ));
267
265
$ this ->assertTrue (!is_file ($ basePath .'file ' ));
268
- $ this ->assertTrue (!is_link ($ basePath .'link ' ));
269
266
}
270
267
271
- public function testRemoveCleansTraversableObjectOfFilesLinksAndDirectories ()
268
+ public function testRemoveCleansTraversableObjectOfFilesAndDirectories ()
272
269
{
273
270
$ basePath = $ this ->workspace .DIRECTORY_SEPARATOR ;
274
271
275
272
mkdir ($ basePath .'dir ' );
276
273
touch ($ basePath .'file ' );
277
- link ($ basePath .'file ' , $ basePath .'link ' );
278
274
279
275
$ files = new \ArrayObject (array (
280
- $ basePath .'dir ' , $ basePath .'file ' , $ basePath . ' link '
276
+ $ basePath .'dir ' , $ basePath .'file '
281
277
));
282
278
283
279
$ this ->filesystem ->remove ($ files );
284
280
285
281
$ this ->assertTrue (!is_dir ($ basePath .'dir ' ));
286
282
$ this ->assertTrue (!is_file ($ basePath .'file ' ));
287
- $ this ->assertTrue (!is_link ($ basePath .'link ' ));
288
283
}
289
284
290
285
public function testRemoveIgnoresNonExistingFiles ()
@@ -368,6 +363,53 @@ public function testRenameThrowsExceptionIfTargetAlreadyExists()
368
363
$ this ->filesystem ->rename ($ file , $ newPath );
369
364
}
370
365
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 );
<
67ED
code>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
+
371
413
/**
372
414
* Returns file permissions as three digits (i.e. 755)
373
415
*
@@ -377,4 +419,11 @@ private function getFilePermisions($filePath)
377
419
{
378
420
return (int ) substr (sprintf ('%o ' , fileperms ($ filePath )), -3 );
379
421
}
422
+
423
+ private function markAsSkippeIfSymlinkIsMissing ()
424
+ {
425
+ if (!function_exists ('symlink ' )) {
426
+ $ this ->markTestSkipped ('symlink is not supported ' );
427
+ }
428
+ }
380
429
}
0 commit comments