Skip to content

Commit a041feb

Browse files
committed
[Filesystem] Added unit tests for rename method.
1 parent 8071859 commit a041feb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,32 @@ public function testChmodChangesModeOfTraversableFileObject()
342342
$this->assertEquals(753, $this->getFilePermisions($directory));
343343
}
344344

345+
public function testRename()
346+
{
347+
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
348+
$newPath = $this->workspace.DIRECTORY_SEPARATOR.'new_file';
349+
touch($file);
350+
351+
$this->filesystem->rename($file, $newPath);
352+
353+
$this->assertFileNotExists($file);
354+
$this->assertFileExists($newPath);
355+
}
356+
357+
/**
358+
* @expectedException \RuntimeException
359+
*/
360+
public function testRenameThrowsExceptionIfTargetAlreadyExists()
361+
{
362+
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
363+
$newPath = $this->workspace.DIRECTORY_SEPARATOR.'new_file';
364+
365+
touch($file);
366+
touch($newPath);
367+
368+
$this->filesystem->rename($file, $newPath);
369+
}
370+
345371
/**
346372
* Returns file permissions as three digits (i.e. 755)
347373
*

0 commit comments

Comments
 (0)