Skip to content

Commit

Permalink
[FrameworkBundle] Add unit tests for the CacheTemplateLocator class
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Apr 8, 2011
1 parent 27a327e commit c45d5c8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
Expand Up @@ -55,10 +55,20 @@ public function locate($template, $currentPath = null, $first = true)
{
$key = $template->getSignature();

if (!isset($this->templates[$key])) {
return parent::locate($template, $currentPath, $first);
}
$path = $this->getCachedTemplatePath($key);

return $path === null ? parent::locate($template) : $path;
}

return $this->templates[$key];
/**
* Returns the template path from the cache
*
* @param string $key The template signature
*
* @return string|null The path when it is present in the call, false otherwise
*/
protected function getCachedTemplatePath($key)
{
return isset($this->templates[$key]) ? $this->templates[$key] : null;
}
}
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Loader;

use Symfony\Bundle\FrameworkBundle\Templating\Loader\CachedTemplateLocator;
use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;

class CachedTemplateLocatorTest extends TestCase
{
public function testLocateACachedTemplate()
{
$template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine');

$locator = $this
->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\Loader\CachedTemplateLocator')
->setMethods(array('getCachedTemplatePath'))
->disableOriginalConstructor()
->getMock()
;

$locator
->expects($this->once())
->method('getCachedTemplatePath')
->with($template->getSignature())
->will($this->returnValue('/cached/path/to/template'))
;

$this->assertEquals('/cached/path/to/template', $locator->locate($template));
}
}

0 comments on commit c45d5c8

Please sign in to comment.