From 0a016a7d521db704e40041e693e39082c73e836f Mon Sep 17 00:00:00 2001 From: Hari KT Date: Sun, 26 Oct 2014 16:25:05 +0530 Subject: [PATCH] TemplateRegistry map should pass the array via set to make the file inside a closure. Else Fatal error: Call to a member function bindTo() on a non-object --- src/TemplateRegistry.php | 4 +++- tests/unit/src/ViewTest.php | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/TemplateRegistry.php b/src/TemplateRegistry.php index ba37591..3f5b411 100644 --- a/src/TemplateRegistry.php +++ b/src/TemplateRegistry.php @@ -37,7 +37,9 @@ class TemplateRegistry */ public function __construct(array $map = array()) { - $this->map = $map; + foreach ($map as $name => $spec) { + $this->set($name, $spec); + } } /** diff --git a/tests/unit/src/ViewTest.php b/tests/unit/src/ViewTest.php index e02fe91..b2fffbd 100644 --- a/tests/unit/src/ViewTest.php +++ b/tests/unit/src/ViewTest.php @@ -132,4 +132,17 @@ public function testSections() $expect = 'foo bar baz dib zim gir irk'; $this->assertSame($expect, $actual); } + + public function testMapFilesToTemplateRegistryOnConstruct() + { + $view = new View( + new TemplateRegistry(array('foo' => __DIR__ . '/foo_template.php')), + new TemplateRegistry, + new HelperRegistry + ); + $view->setView('foo'); + $actual = $view->__invoke(); + $expect = 'Hello Foo!'; + $this->assertSame($expect, $actual); + } }