From 643a99efa2e67c2a7aa45cfa9e11b4402a0a45ff Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 1 Feb 2013 10:50:01 -0600 Subject: [PATCH] Ensure run() always returns Application instance - Some paths through `Application::run()` would call `return $this->completeRequest($event)`; this particular method was returning a response object, which meant that `send()` was resulting in a double-render. The main `run()` routine typically returns the Application instance, where `send()` is a no-op, and thus no double-render can occur. - The workaround until this is merged and released is to remove the call to `->send()` in your `public/index.php`. --- library/Zend/Mvc/Application.php | 4 ++-- tests/ZendTest/Mvc/ApplicationTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/library/Zend/Mvc/Application.php b/library/Zend/Mvc/Application.php index 652de2d8624..fc49693fe09 100644 --- a/library/Zend/Mvc/Application.php +++ b/library/Zend/Mvc/Application.php @@ -324,7 +324,7 @@ public function send() * event object. * * @param MvcEvent $event - * @return ResponseInterface + * @return Application */ protected function completeRequest(MvcEvent $event) { @@ -332,6 +332,6 @@ protected function completeRequest(MvcEvent $event) $event->setTarget($this); $events->trigger(MvcEvent::EVENT_RENDER, $event); $events->trigger(MvcEvent::EVENT_FINISH, $event); - return $event->getResponse(); + return $this; } } diff --git a/tests/ZendTest/Mvc/ApplicationTest.php b/tests/ZendTest/Mvc/ApplicationTest.php index 5b10cf25940..651d80d3622 100644 --- a/tests/ZendTest/Mvc/ApplicationTest.php +++ b/tests/ZendTest/Mvc/ApplicationTest.php @@ -12,6 +12,7 @@ use ArrayObject; use PHPUnit_Framework_TestCase as TestCase; +use ReflectionObject; use stdClass; use Zend\Config\Config; use Zend\Http\Request; @@ -644,4 +645,16 @@ public function testReturnsResponseFromListenerWhenDispatchEventShortCircuits() $this->application->run(); $this->assertTrue($triggered); } + + public function testCompleteRequestShouldReturnApplicationInstance() + { + $r = new ReflectionObject($this->application); + $method = $r->getMethod('completeRequest'); + $method->setAccessible(true); + + $this->application->bootstrap(); + $event = $this->application->getMvcEvent(); + $result = $method->invoke($this->application, $event); + $this->assertSame($this->application, $result); + } }