Does vfsStream allow unlink empty dir?

382 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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 case unlink() is applied on a directory.