From 253f8136c5dc3d1a4a8d663e9f1a3641114b31bc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Haso=C5=88?= Date: Thu, 3 Nov 2011 12:01:29 +0100 Subject: [PATCH] added an exception for undefined templates in ArrayLoader::isFresh --- lib/Twig/Loader/Array.php | 4 ++++ test/Twig/Tests/Loader/ArrayTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 0 deletions(-) diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index e8dc160..962d64c 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -90,6 +90,10 @@ class Twig_Loader_Array implements Twig_LoaderInterface */ public function isFresh($name, $time) { + if (!isset($this->templates[$name])) { + throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); + } + return true; } } diff --git a/test/Twig/Tests/Loader/ArrayTest.php b/test/Twig/Tests/Loader/ArrayTest.php index 38a8f89..ae7648f 100644 --- a/test/Twig/Tests/Loader/ArrayTest.php +++ b/test/Twig/Tests/Loader/ArrayTest.php @@ -58,4 +58,14 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase $loader = new Twig_Loader_Array(array('foo' => 'bar')); $this->assertTrue($loader->isFresh('foo', time())); } + + /** + * @expectedException Twig_Error_Loader + */ + public function testIsFreshWhenTemplateDoesNotExist() + { + $loader = new Twig_Loader_Array(array()); + + $loader->isFresh('foo', time()); + } } -- 1.7.2.5