vfsStream 是否允许取消链接空目录?
我的单元测试尝试删除一个空目录。被测试的类使用unlink(先前测试的结果)。如果我在没有 vfsStream 的情况下编写相同的代码,我无法删除空目录。
单元测试:
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'));
}
}
生产代码:
class Recursive_Delete
{
private $_file;
public function __construct($file)
{
$this->_file = $file;
}
public function delete()
{
unlink($this->_file);
}
}
这是一个错误还是我错过了什么? 谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 vfsStream 0.10.0 及之前版本中的一个错误,它允许在目录上使用
unlink()
。该错误已在即将发布的版本 0.11.0 中修复,请参阅 https://github.com/mikey179/vfsStream /issues/23。现在,如果unlink()
应用于目录,将会抛出警告。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.