diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index a63c5a313f..76dab0354a 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -128,6 +128,7 @@ class Filesystem * @param string $target The new filename * * @throws \RuntimeException When target file already exists + * @throws \RuntimeException When origin cannot be renamed */ public function rename($origin, $target) { @@ -136,7 +137,9 @@ class Filesystem throw new \RuntimeException(sprintf('Cannot rename because the target "%s" already exist.', $target)); } - rename($origin, $target); + if (false === @rename($origin, $target)) { + throw new \RuntimeException(sprintf('Cannot rename "%s" to "%s".', $origin, $target)); + } } /** diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 80b5167231..f1c8808dbf 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -379,6 +379,17 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase $this->filesystem->rename($file, $newPath); } + /** + * @expectedException \RuntimeException + */ + public function testRenameThrowsExceptionOnError() + { + $file = $this->workspace.DIRECTORY_SEPARATOR.uniqid(); + $newPath = $this->workspace.DIRECTORY_SEPARATOR.'new_file'; + + $this->filesystem->rename($file, $newPath); + } + public function testSymlink() { $this->markAsSkippeIfSymlinkIsMissing();