From e495f5765a96f1d4d7015f082aa2ff7174952ec5 Mon Sep 17 00:00:00 2001 From: adlawson Date: Fri, 24 Jul 2015 17:14:08 +0100 Subject: [PATCH] Add link node factory methods --- src/Node/Factory/NodeFactory.php | 13 ++++++++++--- src/Node/Factory/NodeFactoryInterface.php | 14 +++++++++++--- test/unit/Node/Factory/NodeFactoryTest.php | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/Node/Factory/NodeFactory.php b/src/Node/Factory/NodeFactory.php index fb8bb8f..ee7370d 100644 --- a/src/Node/Factory/NodeFactory.php +++ b/src/Node/Factory/NodeFactory.php @@ -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) diff --git a/src/Node/Factory/NodeFactoryInterface.php b/src/Node/Factory/NodeFactoryInterface.php index fa498a4..9ab3a05 100644 --- a/src/Node/Factory/NodeFactoryInterface.php +++ b/src/Node/Factory/NodeFactoryInterface.php @@ -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 diff --git a/test/unit/Node/Factory/NodeFactoryTest.php b/test/unit/Node/Factory/NodeFactoryTest.php index 5b97492..b67ff61 100644 --- a/test/unit/Node/Factory/NodeFactoryTest.php +++ b/test/unit/Node/Factory/NodeFactoryTest.php @@ -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([