From 239eef982859a4a5737c11c155e685a4a3a39d61 Mon Sep 17 00:00:00 2001 From: Rudolph Gottesheim Date: Mon, 20 Mar 2017 11:27:26 +0100 Subject: [PATCH 1/3] PhpRendererStrategy should be able to handle an event w/o a response ViewEvent#getResponse() may return null, but PhpRendererStrategy#injectResponse() didn't handle that case. --- src/Strategy/PhpRendererStrategy.php | 4 ++-- test/Strategy/PhpRendererStrategyTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Strategy/PhpRendererStrategy.php b/src/Strategy/PhpRendererStrategy.php index 5f5ee242..e6602d92 100644 --- a/src/Strategy/PhpRendererStrategy.php +++ b/src/Strategy/PhpRendererStrategy.php @@ -103,12 +103,12 @@ public function selectRenderer(ViewEvent $e) public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); - if ($renderer !== $this->renderer) { + $response = $e->getResponse(); + if ($renderer !== $this->renderer || $response === null) { return; } $result = $e->getResult(); - $response = $e->getResponse(); // Set content // If content is empty, check common placeholders to determine if they are diff --git a/test/Strategy/PhpRendererStrategyTest.php b/test/Strategy/PhpRendererStrategyTest.php index 69470570..10e44fd8 100644 --- a/test/Strategy/PhpRendererStrategyTest.php +++ b/test/Strategy/PhpRendererStrategyTest.php @@ -21,6 +21,9 @@ class PhpRendererStrategyTest extends TestCase { use EventListenerIntrospectionTrait; + /** @var PhpRendererStrategy */ + private $strategy; + public function setUp() { $this->renderer = new PhpRenderer; @@ -168,4 +171,14 @@ public function testDetachesListeners() $listeners = iterator_to_array($this->getListenersForEvent('response', $events)); $this->assertCount(0, $listeners); } + + public function testInjectResponseWorksWithAnEventWithNoResponse() + { + $e = new ViewEvent(); + $e->setRenderer($this->strategy->getRenderer()); + + $this->strategy->injectResponse($e); + + $this->assertNull($e->getResponse()); + } } From 916dfe7f1f27b4589acf10dc67bcd572b91bebff Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 20 Mar 2017 13:03:50 -0500 Subject: [PATCH 2/3] CS fixes per phpcs --- test/Helper/HeadMetaTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Helper/HeadMetaTest.php b/test/Helper/HeadMetaTest.php index face4778..991e395f 100644 --- a/test/Helper/HeadMetaTest.php +++ b/test/Helper/HeadMetaTest.php @@ -434,7 +434,8 @@ public function testCharsetPosition() $this->assertEquals( '' . PHP_EOL . '', - $view->plugin('headMeta')->toString()); + $view->plugin('headMeta')->toString() + ); } /** From 5bd9b2f4aa4887a9a2c5f68a45604226762abbe1 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 20 Mar 2017 13:05:07 -0500 Subject: [PATCH 3/3] Added CHANGELOG for #112 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 440727b8..487f38c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ All notable changes to this project will be documented in this file, in reverse - [#104](https://github.com/zendframework/zend-view/pull/104) fixes the `@method` annotation for the `Placeholder` view helper to use the correct case, fixing issues with method completion in IDEs. +- [#112](https://github.com/zendframework/zend-view/pull/112) fixes an issue in + the `PhpRendererStrategy` whereby absence of a response instance in the + `ViewEvent` would lead to a fatal error. ## 2.8.1 - 2016-06-30