Skip to content

Commit

Permalink
Better approach to exception handling in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igorw committed Jun 29, 2012
1 parent fa4a27e commit cf4d355
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/app.php
Expand Up @@ -81,6 +81,10 @@
->assert('id', '[0-9a-f]{8}'); ->assert('id', '[0-9a-f]{8}');


$app->error(function (Exception $e) use ($app) { $app->error(function (Exception $e) use ($app) {
if (!$app['catch_exceptions']) {
return;
}

$code = ($e instanceof HttpException) ? $e->getStatusCode() : 500; $code = ($e instanceof HttpException) ? $e->getStatusCode() : 500;


return new Response($app['twig']->render('error.html', array( return new Response($app['twig']->render('error.html', array(
Expand Down
8 changes: 7 additions & 1 deletion tests/FunctionalTest.php
Expand Up @@ -8,9 +8,13 @@ public function createApplication()
{ {
$app = require __DIR__.'/../src/app.php'; $app = require __DIR__.'/../src/app.php';


$app['catch_exceptions'] = false;

$app['app.storage'] = $this->getMockBuilder('Igorw\Trashbin\Storage')->disableOriginalConstructor()->getMock(); $app['app.storage'] = $this->getMockBuilder('Igorw\Trashbin\Storage')->disableOriginalConstructor()->getMock();


unset($this->app['exception_handler']); $app['twig.options'] = array('debug' => true);

unset($app['exception_handler']);


return $app; return $app;
} }
Expand Down Expand Up @@ -94,6 +98,8 @@ public function testViewPaste()


public function testViewPasteWithInvalidId() public function testViewPasteWithInvalidId()
{ {
$this->app['catch_exceptions'] = true;

$this->app['app.storage'] $this->app['app.storage']
->expects($this->once()) ->expects($this->once())
->method('get') ->method('get')
Expand Down

0 comments on commit cf4d355

Please sign in to comment.