Navigation Menu

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

Commit

Permalink
Merge branch 'hotfix/2981'
Browse files Browse the repository at this point in the history
Close #2981
  • Loading branch information
weierophinney committed Nov 19, 2012
2 parents a2facc2 + 1de8886 commit d8a736b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/Zend/Mvc/Application.php
Expand Up @@ -280,6 +280,7 @@ public function run()
$response = $result->last();
if ($response instanceof ResponseInterface) {
$event->setTarget($this);
$event->setResponse($response);
$events->trigger(MvcEvent::EVENT_FINISH, $event);
return $response;
}
Expand All @@ -299,6 +300,7 @@ public function run()
$response = $result->last();
if ($response instanceof ResponseInterface) {
$event->setTarget($this);
$event->setResponse($response);
$events->trigger(MvcEvent::EVENT_FINISH, $event);
return $response;
}
Expand Down
52 changes: 52 additions & 0 deletions tests/ZendTest/Mvc/ApplicationTest.php
Expand Up @@ -576,4 +576,56 @@ public function testOnDispatchErrorEventPassedToTriggersShouldBeTheOriginalOne()
$event = $this->application->getMvcEvent();
$this->assertInstanceOf('Zend\View\Model\ViewModel', $event->getResult());
}

/**
* @group 2981
*/
public function testReturnsResponseFromListenerWhenRouteEventShortCircuits()
{
$this->application->bootstrap();
$testResponse = new Response();
$response = $this->application->getResponse();
$events = $this->application->getEventManager();
$events->clearListeners(MvcEvent::EVENT_DISPATCH);
$events->attach(MvcEvent::EVENT_ROUTE, function ($e) use ($testResponse) {
$testResponse->setContent('triggered');
return $testResponse;
}, 100);

$self = $this;
$triggered = false;
$events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($self, $testResponse, &$triggered) {
$self->assertSame($testResponse, $e->getResponse());
$triggered = true;
});

$this->application->run();
$this->assertTrue($triggered);
}

/**
* @group 2981
*/
public function testReturnsResponseFromListenerWhenDispatchEventShortCircuits()
{
$this->application->bootstrap();
$testResponse = new Response();
$response = $this->application->getResponse();
$events = $this->application->getEventManager();
$events->clearListeners(MvcEvent::EVENT_ROUTE);
$events->attach(MvcEvent::EVENT_DISPATCH, function ($e) use ($testResponse) {
$testResponse->setContent('triggered');
return $testResponse;
}, 100);

$self = $this;
$triggered = false;
$events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($self, $testResponse, &$triggered) {
$self->assertSame($testResponse, $e->getResponse());
$triggered = true;
});

$this->application->run();
$this->assertTrue($triggered);
}
}

0 comments on commit d8a736b

Please sign in to comment.