My unit test tries to remove an empty dir. The class under test uses unlink (result of a previous test). If I write the same code without vfsStream I cannot remove the empty dir.
Unit test:
require 'vfsStream/vfsStream.php';
require '../Classes/Recursive/Delete.php';
class Recursive_Delete_Test extends PHPUnit_Framework_TestCase {
// More tests!
public function testShouldRemoveAnEmptyDirectory()
{
vfsStream::setup();
vfsStreamWrapper::getRoot()->addChild(vfsStream::newDirectory('dir'));
$recursiveDelete = new Recursive_Delete(vfsStream::url('root/dir'));
$recursiveDelete->delete();
$this->assertFileNotExists(vfsStream::url('root/dir'));
}
}
Production code:
class Recursive_Delete
{
private $_file;
public function __construct($file)
{
$this->_file = $file;
}
public function delete()
{
unlink($this->_file);
}
}
Is it a bug or am I missing something? Thanks.
This is a bug in vfsStream up to 0.10.0 which allows
unlink()
on directories. The bug is fixed in upcoming release 0.11.0, see https://github.com/mikey179/vfsStream/issues/23. Now a warning will be thrown in caseunlink()
is applied on a directory.