atoum/atoum — pull request #151 by jubianchi (2012-12-02 15:53:12+00:00)
Title: [DRAFT] Add filesystem API above atoum's stream

**This PR is not meant to be merged as is. It's here for discussion purpose only.**
_There are also many CS fix to apply..._

This PR adds a simple API above atoum's stream to build fake filesystem used in tests.

Currently this API only lets us create simple trees containing directories and files. We can then assert on these using the standard adapter and streams asserters.

I'm not fully satisfied of it, especially the ```referencedBy```method which lets us get a reference to a node.

The filesystem should also be improved to allow on th fly nodes manipulation (create, delete, ...). In this version, if you remove the ```->directory('foobar')->close()``` line, the ```mkdir```call would throw an error and if you keep this line, ```mkdir``` returns false as the directory already exists.

Usage : ```tests/units/RecursiveDirectoryIterator.php````
```php
filesystem === null) {
$this->filesystem = stream::get();
}
}

public function directory() {

}

public function test__construct()
{
$this
->if($filesystem = $directory = $otherDirectory = $subdirectory = $file = null)
->mockFilesystem('foo')
->referencedBy($filesystem)
->directory('foobar')->close()
->directory('bar')
->referencedBy($directory)
->close()
->directory('baz')
->referencedBy($otherDirectory)
->directory('boo')
->referencedBy($subdirectory)
->file('file')
->referencedBy($file)
->content($content = uniqid())
->close()
->close()
->close()
->close()
->and($object = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($filesystem)))
->and(call_user_func(function() use($object) { foreach($object as $v) {} }))
->then
->boolean(is_dir($filesystem . DIRECTORY_SEPARATOR . 'foobar'))->isTrue()
->boolean(mkdir($filesystem . DIRECTORY_SEPARATOR . 'foobar'))->isFalse()
->boolean(is_dir($filesystem))->isTrue()
->boolean(is_dir($directory))->isTrue()
->boolean(is_dir($otherDirectory))->isTrue()
->boolean(is_dir($subdirectory))->isTrue()
->adapter($filesystem->getStream())
->call('dir_opendir')->once()
->call('dir_readdir')->exactly(4)
->call('dir_rewinddir')->once()
->adapter($directory->getStream())
->call('dir_opendir')->once()
->call('dir_readdir')->once()
->call('dir_rewinddir')->once()
->call('dir_closedir')->once()
->adapter($otherDirectory->getStream())
->call('dir_opendir')->once()
->call('dir_readdir')->exactly(2)
->call('dir_rewinddir')->once()
->call('dir_closedir')->once()
->adapter($subdirectory->getStream())
->call('dir_opendir')->once()
->call('dir_readdir')->exactly(2)
->call('dir_rewinddir')->once()
->call('dir_closedir')->once()
->adapter($file->getStream())
->call('url_stat')->withArguments((string) $file)

->boolean(is_file($file))->isTrue()
->string(file_get_contents($file))->isEqualTo($content)
->stream($file->getStream())->isRead()
;
}
}
```