This commit is contained in:
Fabien Potencier
2015-10-04 10:38:04 +02:00
parent 3347b9040e
commit aa1596785b
2 changed files with 26 additions and 30 deletions
+6 -7
View File
@@ -11,12 +11,12 @@
class Twig_Tests_Cache_FilesystemTest extends PHPUnit_Framework_TestCase
{
protected $nonce;
protected $classname;
protected $directory;
protected $cache;
private $nonce;
private $classname;
private $directory;
private $cache;
public function setUp()
protected function setUp()
{
$this->nonce = hash('sha256', uniqid(mt_rand(), true));
$this->classname = '__Twig_Tests_Cache_FilesystemTest_Template_'.$this->nonce;
@@ -24,7 +24,7 @@ class Twig_Tests_Cache_FilesystemTest extends PHPUnit_Framework_TestCase
$this->cache = new Twig_Cache_Filesystem($this->directory);
}
public function tearDown()
protected function tearDown()
{
if (file_exists($this->directory)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->directory), RecursiveIteratorIterator::CHILD_FIRST);
@@ -48,7 +48,6 @@ class Twig_Tests_Cache_FilesystemTest extends PHPUnit_Framework_TestCase
$dir = dirname($key);
@mkdir($dir, 0777, true);
$this->assertTrue(is_dir($dir));
$this->assertFalse(class_exists($this->classname, false));
$content = $this->generateSource();
+20 -23
View File
@@ -180,13 +180,12 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
public function testAutoReloadCacheMiss()
{
$template_name = __FUNCTION__;
$template_content = __FUNCTION__;
$templateName = __FUNCTION__;
$templateContent = __FUNCTION__;
$cache = $this->getMock('Twig_CacheInterface');
$loader = $this->getMockLoader($template_name, $template_content);
$options = array('cache' => $cache, 'auto_reload' => true, 'debug' => false);
$twig = new Twig_Environment($loader, $options);
$loader = $this->getMockLoader($templateName, $templateContent);
$twig = new Twig_Environment($loader, array('cache' => $cache, 'auto_reload' => true, 'debug' => false));
// Cache miss: getTimestamp returns 0 and as a result the load() is
// skipped.
@@ -201,18 +200,17 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$cache->expects($this->never())
->method('load');
$twig->loadTemplate($template_name);
$twig->loadTemplate($templateName);
}
public function testAutoReloadCacheHit()
{
$template_name = __FUNCTION__;
$template_content = __FUNCTION__;
$templateName = __FUNCTION__;
$templateContent = __FUNCTION__;
$cache = $this->getMock('Twig_CacheInterface');
$loader = $this->getMockLoader($template_name, $template_content);
$options = array('cache' => $cache, 'auto_reload' => true, 'debug' => false);
$twig = new Twig_Environment($loader, $options);
$loader = $this->getMockLoader($templateName, $templateContent);
$twig = new Twig_Environment($loader, array('cache' => $cache, 'auto_reload' => true, 'debug' => false));
$now = time();
@@ -230,18 +228,17 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$cache->expects($this->once())
->method('load');
$twig->loadTemplate($template_name);
$twig->loadTemplate($templateName);
}
public function testAutoReloadOutdatedCacheHit()
{
$template_name = __FUNCTION__;
$template_content = __FUNCTION__;
$templateName = __FUNCTION__;
$templateContent = __FUNCTION__;
$cache = $this->getMock('Twig_CacheInterface');
$loader = $this->getMockLoader($template_name, $template_content);
$options = array('cache' => $cache, 'auto_reload' => true, 'debug' => false);
$twig = new Twig_Environment($loader, $options);
$loader = $this->getMockLoader($templateName, $templateContent);
$twig = new Twig_Environment($loader, array('cache' => $cache, 'auto_reload' => true, 'debug' => false));
$now = time();
@@ -257,7 +254,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$cache->expects($this->never())
->method('load');
$twig->loadTemplate($template_name);
$twig->loadTemplate($templateName);
}
public function testAddExtension()
@@ -295,17 +292,17 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$this->assertCount(2, $twig->getNodeVisitors());
}
protected function getMockLoader($template_name, $template_content)
protected function getMockLoader($templateName, $templateContent)
{
$loader = $this->getMock('Twig_LoaderInterface');
$loader->expects($this->any())
->method('getSource')
->with($template_name)
->will($this->returnValue($template_content));
->with($templateName)
->will($this->returnValue($templateContent));
$loader->expects($this->any())
->method('getCacheKey')
->with($template_name)
->will($this->returnValue($template_name));
->with($templateName)
->will($this->returnValue($templateName));
return $loader;
}