Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Ensure run() always returns Application instance
Browse files Browse the repository at this point in the history
- 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`.
  • Loading branch information
weierophinney committed Feb 1, 2013
1 parent 937098e commit 643a99e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/Zend/Mvc/Application.php
Expand Up @@ -324,14 +324,14 @@ public function send()
* event object.
*
* @param MvcEvent $event
* @return ResponseInterface
* @return Application
*/
protected function completeRequest(MvcEvent $event)
{
$events = $this->getEventManager();
$event->setTarget($this);
$events->trigger(MvcEvent::EVENT_RENDER, $event);
$events->trigger(MvcEvent::EVENT_FINISH, $event);
return $event->getResponse();
return $this;
}
}
13 changes: 13 additions & 0 deletions tests/ZendTest/Mvc/ApplicationTest.php
Expand Up @@ -12,6 +12,7 @@

use ArrayObject;
use PHPUnit_Framework_TestCase as TestCase;
use ReflectionObject;
use stdClass;
use Zend\Config\Config;
use Zend\Http\Request;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 643a99e

Please sign in to comment.