Permalink
Browse files

Fix bug with removing folders.

  • Loading branch information...
1 parent 408ca9d commit 46692403d9fe41d6fa6c40a1d04091fa6c7cf367 @reinink reinink committed Sep 27, 2014
Showing with 42 additions and 10 deletions.
  1. +16 −0 src/Template/Folders.php
  2. +16 −0 tests/EngineTest.php
  3. +10 −10 tests/Template/FoldersTest.php
@@ -34,6 +34,22 @@ public function add($name, $path, $fallback = false)
}
/**
+ * Remove a template folder.
+ * @param string $name
+ * @return Folders
+ */
+ public function remove($name)
+ {
+ if (!$this->exists($name)) {
+ throw new LogicException('The template folder "' . $name . '" was not found.');
+ }
+
+ unset($this->folders[$name]);
+
+ return $this;
+ }
+
+ /**
* Get a template folder.
* @param string $name
* @return Folder
View
@@ -87,6 +87,22 @@ public function testAddFolderWithInvalidDirectory()
$this->engine->addFolder('namespace', vfsStream::url('does/not/exist'));
}
+ public function testRemoveFolder()
+ {
+ vfsStream::create(
+ array(
+ 'folder' => array(
+ 'template.php' => ''
+ )
+ )
+ );
+
+ $this->engine->addFolder('folder', vfsStream::url('templates/folder'));
+ $this->assertEquals($this->engine->getFolders()->exists('folder'), true);
+ $this->assertInstanceOf('League\Plates\Engine', $this->engine->removeFolder('folder'));
+ $this->assertEquals($this->engine->getFolders()->exists('folder'), false);
+ }
+
public function testGetFolders()
{
$this->assertInstanceOf('League\Plates\Template\Folders', $this->engine->getFolders());
@@ -22,16 +22,8 @@ public function testCanCreateInstance()
public function testAddFolder()
{
- vfsStream::create(
- array(
- 'folder' => array(
- 'template.php' => ''
- )
- )
- );
-
- $this->assertInstanceOf('League\Plates\Template\Folders', $this->folders->add('name', vfsStream::url('templates/folder')));
- $this->assertEquals($this->folders->get('name')->getPath(), 'vfs://templates/folder');
+ $this->assertInstanceOf('League\Plates\Template\Folders', $this->folders->add('name', vfsStream::url('templates')));
+ $this->assertEquals($this->folders->get('name')->getPath(), 'vfs://templates');
}
public function testAddFolderWithNamespaceConflict()
@@ -47,6 +39,14 @@ public function testAddFolderWithInvalidDirectory()
$this->folders->add('name', vfsStream::url('does/not/exist'));
}
+ public function testRemoveFolder()
+ {
+ $this->folders->add('folder', vfsStream::url('templates'));
+ $this->assertEquals($this->folders->exists('folder'), true);
+ $this->assertInstanceOf('League\Plates\Template\Folders', $this->folders->remove('folder'));
+ $this->assertEquals($this->folders->exists('folder'), false);
+ }
+
public function testGetFolder()
{
$this->folders->add('name', vfsStream::url('templates'));

0 comments on commit 4669240

Please sign in to comment.