Permalink
Browse files

Merge branch 'hotfix/3421' into develop

Close #3421
  • Loading branch information...
weierophinney committed Jan 14, 2013
2 parents 577b1da + 2c5196a commit 50ee03ce20a6ba62c567c0cfddb02585cd92d160
@@ -158,9 +158,15 @@ public function prepareExceptionViewModel(MvcEvent $e)
$response = $e->getResponse();
if (!$response) {
$response = new HttpResponse();
+ $response->setStatusCode(500);
$e->setResponse($response);
+ } else {
+ $statusCode = $response->getStatusCode();
+ if ($statusCode === 200) {
+ $response->setStatusCode(500);
+ }
}
- $response->setStatusCode(500);
+
break;
}
}
@@ -169,4 +169,25 @@ public function testDetachesListeners()
$listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
$this->assertEquals(0, count($listeners));
}
+
+ public function testReuseResponseStatusCodeIfItExists()
+ {
+ $event = new MvcEvent();
+ $response = new Response();
+ $response->setStatusCode(401);
+ $event->setResponse($response);
+ $this->strategy->prepareExceptionViewModel($event);
+ $response = $event->getResponse();
+ if (null !== $response) {
+ $this->assertEquals(401, $response->getStatusCode());
+ }
+ $model = $event->getResult();
+ if (null !== $model) {
+ $variables = $model->getVariables();
+ $this->assertArrayNotHasKey('message', $variables);
+ $this->assertArrayNotHasKey('exception', $variables);
+ $this->assertArrayNotHasKey('display_exceptions', $variables);
+ $this->assertNotEquals('error', $model->getTemplate());
+ }
+ }
}

0 comments on commit 50ee03c

Please sign in to comment.