diff --git a/src/deit/filesystem/Filesystem.php b/src/deit/filesystem/Filesystem.php index 4756fc6..840fc29 100644 --- a/src/deit/filesystem/Filesystem.php +++ b/src/deit/filesystem/Filesystem.php @@ -248,7 +248,7 @@ public function remove($path) { } else { //remove the file if it exists - if (is_file($path)) { + if (is_file($path) || is_link($path)) { if (!unlink($path)) { throw new \Exception(sprintf('Unable to delete file "%s".', $path)); } @@ -291,4 +291,4 @@ public function setContent($file, $content) { } } - \ No newline at end of file + diff --git a/tests/deit/filesystem/FilesystemTest.php b/tests/deit/filesystem/FilesystemTest.php new file mode 100644 index 0000000..545aa8c --- /dev/null +++ b/tests/deit/filesystem/FilesystemTest.php @@ -0,0 +1,37 @@ + + */ + +class FilesystemTest extends \PHPUnit_Framework_TestCase { + + public function rmdir_recursive($dir) { + foreach(scandir($dir) as $file) { + if ('.' === $file || '..' === $file) continue; + if (is_dir("$dir/$file")) rmdir_recursive("$dir/$file"); + else unlink("$dir/$file"); + } + rmdir($dir); + } + + public function test_symlink_removal() { + + $test_dir = 'tests/test-data/symlinks'; + $test_link = $test_dir . '/points_nowhere'; + + if ( is_dir($test_dir) ) { + $this->rmdir_recursive( $test_dir ); + } + mkdir( $test_dir ); + symlink( "does_not_exist", $test_link ); + + $fs = new Filesystem(); + $fs->remove( $test_dir ); + $this->assertFalse ( is_link($test_link) || is_file($test_link) ); + + } +} diff --git a/tests/deit/filesystem/FinderTest.php b/tests/deit/filesystem/FinderTest.php index 5cb3563..bce6f31 100644 --- a/tests/deit/filesystem/FinderTest.php +++ b/tests/deit/filesystem/FinderTest.php @@ -29,7 +29,7 @@ public function test_files_named() { global $total_files; $finder = new Finder('tests/test-data/bigtree'); - + $this->assertEquals($total_files, count($finder->files())); foreach ($finder->files()->named('#\.json$#') as $path) { @@ -58,10 +58,8 @@ public function test_folders() { public function test_copy() { - $fs = new Filesystem(); - - $f = new Finder('tests/test-data/bigtree'); - $f + $finder = new Finder('tests/test-data/bigtree'); + $finder ->files() ->named('#\.json#') ->copyTo('tests/test-data-copy')