merged branch alessandro1997/issue-3848 (PR #3849)
Commits -------78d6f3f
[Filesystem] Written missing tests.1998f3f
[Filesystem] Added silence operator to rename().7ce5a52
[Filesystem] Fixed docs for rename().3f2865b
[Filesystem] rename() throws RuntimeException on error (fixes #3848). Discussion ---------- [Filesystem] rename() throws RuntimeException on error. Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #3848 --------------------------------------------------------------------------- by alessandro1997 at 2012-04-09T19:32:23Z I have a doubt: I can't write any tests since the rename() function generates a warning if an error occurs. Should I use the silence operator or what else? Maybe @stof could enlighten me?
This commit is contained in:
commit
2a16f84ce5
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user