mirror of https://github.com/adlawson/php-vfs.git
create directory recursively
- Removes call to non-existent method ‘checkBit’ - Uses $recursive option passed as 2nd argument to determine if recursion should occur - Removes unused argument from DirectoryHandle::buildNodesRecursive
This commit is contained in:
parent
ab2a2ad26f
commit
3c4cecc423
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
namespace Vfs\Stream;
|
||||
|
||||
use Vfs\Node\NodeContainerInterface;
|
||||
use Vfs\Exception\UnopenedHandleException;
|
||||
|
||||
class DirectoryHandle extends AbstractHandle
|
||||
|
@ -32,9 +33,9 @@ class DirectoryHandle extends AbstractHandle
|
|||
|
||||
if (!$this->node) {
|
||||
$parentPath = dirname($this->path);
|
||||
$parent = $this->fs->get($parentPath);
|
||||
|
||||
if (!$parent && $this->checkBit($options, STREAM_MKDIR_RECURSIVE)) {
|
||||
$parent = $this->fs->get($parentPath);
|
||||
if (!$parent && (boolean) $recursive) {
|
||||
$parent = $this->buildNodesRecursive($this->fs->get('/'), $this->path);
|
||||
}
|
||||
|
||||
|
@ -114,10 +115,9 @@ class DirectoryHandle extends AbstractHandle
|
|||
|
||||
/**
|
||||
* @param NodeContainerInterface $root
|
||||
* @param string $path
|
||||
* @return NodeContainerInterface
|
||||
*/
|
||||
protected function buildNodesRecursive(NodeContainerInterface $root, $path)
|
||||
protected function buildNodesRecursive(NodeContainerInterface $root)
|
||||
{
|
||||
$factory = $this->fs->getNodeFactory();
|
||||
$walker = $this->fs->getNodeWalker();
|
||||
|
|
|
@ -50,4 +50,30 @@ class DirectoryHandleTest extends UnitTestCase
|
|||
|
||||
$handle->rename('foo://bar');
|
||||
}
|
||||
|
||||
public function testCreateRecursively()
|
||||
{
|
||||
$handle = new DirectoryHandle($this->fs, 'foo://foo/bar');
|
||||
|
||||
$rootContainer = Mockery::mock('Vfs\Node\NodeContainerInterface');
|
||||
$builtDir = Mockery::Mock('Vfs\Node\Directory');
|
||||
$builtContainer = Mockery::mock('Vfs\Node\NodeContainerInterface');
|
||||
$nodeFactory = Mockery::mock('Vfs\Node\NodeFactoryInterface');
|
||||
$nodeWalker = Mockery::mock('Vfs\Node\NodeWalkerInterface');
|
||||
|
||||
$builtContainer->shouldReceive('add')->with(basename('/foo/bar'), $builtDir);
|
||||
$nodeFactory->shouldReceive('buildDirectory')->andReturn($builtDir);
|
||||
$nodeWalker->shouldReceive('walkPath')->once()->andReturn($builtContainer);
|
||||
|
||||
$this->fs->shouldReceive('get')->once()->with('/foo/bar');
|
||||
$this->fs->shouldReceive('get')->once()->with('/foo');
|
||||
|
||||
|
||||
$this->fs->shouldReceive('get')->once()->with('/')->andReturn($rootContainer);
|
||||
$this->fs->shouldReceive('getNodeFactory')->times(2)->andReturn($nodeFactory);
|
||||
$this->fs->shouldReceive('getNodeWalker')->once()->andReturn($nodeWalker);
|
||||
|
||||
|
||||
$handle->create(0777, true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue