【发布时间】:2015-12-31 10:41:55
【问题描述】:
vfsStream的用例如下:
$directories = explode('/', 'path/to/some/dir');
$structure = [];
$reference =& $structure;
foreach ($directories as $directory) {
$reference[$directory] = [];
$reference =& $reference[$directory];
}
vfsStream::setup();
$root = vfsStream::create($structure);
$file = vfsStream::newFile('file')
->at($root) //should changes be introduced here?
->setContent($content = 'Some content here');
vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure() 的输出是
Array
(
[root] => Array
(
[path] => Array
(
[to] => Array
(
[some] => Array
(
[dir] => Array
(
)
)
)
)
[file] => Some content here
)
)
是否可以将文件插入特定目录,例如dir 目录下?
【问题讨论】:
-
最简单的方法是,在阅读了一些文档之后,似乎实际上在一开始就在结构中构建了文件。为什么建结构的时候不能定义呢?
-
@FélixGagnon-Grenier 是的,这是可能的;但是我寻求给定情况的解决方案。想知道这是否可以通过任何方式实现?
标签: php unit-testing oop phpunit vfs-stream