added an exception for undefined templates in ArrayLoader::isFresh
authorMartin Hasoň <hason@itstudio.cz>
Thu, 3 Nov 2011 11:01:29 +0000 (12:01 +0100)
committerMartin Hasoň <hason@itstudio.cz>
Thu, 3 Nov 2011 11:01:29 +0000 (12:01 +0100)
lib/Twig/Loader/Array.php
test/Twig/Tests/Loader/ArrayTest.php

index e8dc160..962d64c 100644 (file)
@@ -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;
     }
 }
index 38a8f89..ae7648f 100644 (file)
@@ -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());
+    }
 }