mirror of
https://github.com/adlawson/php-vfs.git
synced 2024-11-24 21:57:40 +00:00
Add link node factory methods
This commit is contained in:
parent
09a70ad1f0
commit
e495f5765a
@ -11,9 +11,11 @@ namespace Vfs\Node\Factory;
|
||||
|
||||
use LogicException;
|
||||
use Vfs\Node\Directory;
|
||||
use Vfs\Node\DirectoryLink;
|
||||
use Vfs\Node\File;
|
||||
use Vfs\Node\FileLink;
|
||||
use Vfs\Node\FileInterface;
|
||||
use Vfs\Node\NodeContainerInterface;
|
||||
use Vfs\Node\NodeInterface;
|
||||
|
||||
class NodeFactory implements NodeFactoryInterface
|
||||
{
|
||||
@ -22,14 +24,19 @@ class NodeFactory implements NodeFactoryInterface
|
||||
return new Directory($children);
|
||||
}
|
||||
|
||||
public function buildDirectoryLink(NodeContainerInterface $target)
|
||||
{
|
||||
return new DirectoryLink($target);
|
||||
}
|
||||
|
||||
public function buildFile($content = '')
|
||||
{
|
||||
return new File($content);
|
||||
}
|
||||
|
||||
public function buildLink($content = '')
|
||||
public function buildFileLink(FileInterface $target)
|
||||
{
|
||||
throw new LogicException('Symlinks aren\'t supported yet.');
|
||||
return new FileLink($target);
|
||||
}
|
||||
|
||||
public function buildTree(array $tree)
|
||||
|
@ -9,6 +9,8 @@
|
||||
*/
|
||||
namespace Vfs\Node\Factory;
|
||||
|
||||
use Vfs\Node\FileInterface;
|
||||
use Vfs\Node\LinkInterface;
|
||||
use Vfs\Node\NodeContainerInterface;
|
||||
use Vfs\Node\NodeInterface;
|
||||
|
||||
@ -20,6 +22,12 @@ interface NodeFactoryInterface
|
||||
*/
|
||||
public function buildDirectory(array $children = []);
|
||||
|
||||
/**
|
||||
* @param NodeContainerInterface $target
|
||||
* @return LinkInterface
|
||||
*/
|
||||
public function buildDirectoryLink(NodeContainerInterface $target);
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @return NodeInterface
|
||||
@ -27,10 +35,10 @@ interface NodeFactoryInterface
|
||||
public function buildFile($content = '');
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @return NodeInterface
|
||||
* @param FileInterface $file
|
||||
* @return LinkInterface
|
||||
*/
|
||||
public function buildLink($content = '');
|
||||
public function buildFileLink(FileInterface $target);
|
||||
|
||||
/**
|
||||
* @param array $tree
|
||||
|
@ -2,6 +2,8 @@
|
||||
namespace Vfs\Node\Factory;
|
||||
|
||||
use Mockery;
|
||||
use Vfs\Node\Directory;
|
||||
use Vfs\Node\File;
|
||||
use Vfs\Test\UnitTestCase;
|
||||
|
||||
class NodeFactoryTest extends UnitTestCase
|
||||
@ -24,6 +26,15 @@ class NodeFactoryTest extends UnitTestCase
|
||||
$this->assertEquals('foo', $file->getContent());
|
||||
}
|
||||
|
||||
public function testBuildFileLink()
|
||||
{
|
||||
$file = new File();
|
||||
$link = $this->factory->buildFileLink($file);
|
||||
|
||||
$this->assertInstanceOf('Vfs\Node\FileInterface', $link);
|
||||
$this->assertInstanceOf('Vfs\Node\LinkInterface', $link);
|
||||
}
|
||||
|
||||
public function testBuildDirectory()
|
||||
{
|
||||
$node = Mockery::mock('Vfs\Node\NodeInterface');
|
||||
@ -33,6 +44,15 @@ class NodeFactoryTest extends UnitTestCase
|
||||
$this->assertSame($node, $dir->get('foo'));
|
||||
}
|
||||
|
||||
public function testBuildDirectoryLink()
|
||||
{
|
||||
$dir = new Directory();
|
||||
$link = $this->factory->buildDirectoryLink($dir);
|
||||
|
||||
$this->assertInstanceOf('Vfs\Node\NodeContainerInterface', $link);
|
||||
$this->assertInstanceOf('Vfs\Node\LinkInterface', $link);
|
||||
}
|
||||
|
||||
public function testBuildTree()
|
||||
{
|
||||
$root = $this->factory->buildTree([
|
||||
|
Loading…
Reference in New Issue
Block a user