Skip to content

Commit

Permalink
Fix bug with removing folders.
Browse files Browse the repository at this point in the history
  • Loading branch information
reinink committed Sep 27, 2014
1 parent 408ca9d commit 4669240
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/Template/Folders.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ public function add($name, $path, $fallback = false)
return $this;
}

/**
* 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
Expand Down
16 changes: 16 additions & 0 deletions tests/EngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
20 changes: 10 additions & 10 deletions tests/Template/FoldersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'));
Expand Down

0 comments on commit 4669240

Please sign in to comment.