Browse Source

Revert "Missing templates should raise exceptions."

This reverts commit 64ec05c39ee67949c89a14034d56cda7a4a1a8ab.
I accidentally committed this to the wrong branch. And we have force
push disabled.
Mark Story 10 years ago
parent
commit
73cafe7c7d
2 changed files with 7 additions and 18 deletions
  1. 4 2
      src/View/StringTemplate.php
  2. 3 16
      tests/TestCase/View/StringTemplateTest.php

+ 4 - 2
src/View/StringTemplate.php

@@ -16,7 +16,6 @@ namespace Cake\View;
 
 use Cake\Core\Configure\Engine\PhpConfig;
 use Cake\Core\InstanceConfigTrait;
-use RuntimeException;
 
 /**
  * Provides an interface for registering and inserting
@@ -225,9 +224,12 @@ class StringTemplate
     public function format($name, array $data)
     {
         if (!isset($this->_compiled[$name])) {
-            throw new RuntimeException("Cannot find template named '$name'.");
+            return null;
         }
         list($template, $placeholders) = $this->_compiled[$name];
+        if ($template === null) {
+            return null;
+        }
 
         if (isset($data['templateVars'])) {
             $data += $data['templateVars'];

+ 3 - 16
tests/TestCase/View/StringTemplateTest.php

@@ -95,6 +95,9 @@ class StringTemplateTest extends TestCase
         ];
         $this->template->add($templates);
 
+        $result = $this->template->format('not there', []);
+        $this->assertNull($result);
+
         $result = $this->template->format('text', ['text' => '']);
         $this->assertSame('', $result);
 
@@ -140,22 +143,6 @@ class StringTemplateTest extends TestCase
     }
 
     /**
-     * Test formatting a missing template.
-     *
-     * @expectedException RuntimeException
-     * @expectedExceptionMessage Cannot find template named 'missing'
-     * @return void
-     */
-    public function testFormatMissingTemplate()
-    {
-        $templates = [
-            'text' => '{{text}}',
-        ];
-        $this->template->add($templates);
-        $this->template->format('missing', ['text' => 'missing']);
-    }
-
-    /**
      * Test loading templates files in the app.
      *
      * @return void