Commit 6358f7ef authored by Fabien Potencier's avatar Fabien Potencier

added some tests to avoid regressions in the future

parent b5790ea0
......@@ -46,8 +46,8 @@
{
"package": "symfony/http-kernel",
"version": "dev-master",
"source-reference": "538a38c4919a982c1f68ad129178a0e3bb78a4c5",
"commit-date": "1342173351"
"source-reference": "dc93ba8c91cb4d6de78bb32e9836cf32088f0626",
"commit-date": "1342174453"
},
{
"package": "symfony/routing",
......
......@@ -77,6 +77,34 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(404, $response->getStatusCode());
}
public function testErrorHandlerMethodNotAllowedNoDebug()
{
$app = new Application();
$app['debug'] = false;
$app->get('/foo', function () { return 'foo'; });
$request = Request::create('/foo', 'POST');
$response = $app->handle($request);
$this->assertContains('<title>Whoops, looks like something went wrong.</title>', $response->getContent());
$this->assertEquals(405, $response->getStatusCode());
$this->assertEquals('GET', $response->headers->get('Allow'));
}
public function testErrorHandlerMethodNotAllowedDebug()
{
$app = new Application();
$app['debug'] = true;
$app->get('/foo', function () { return 'foo'; });
$request = Request::create('/foo', 'POST');
$response = $app->handle($request);
$this->assertContains('No route found for "POST /foo": Method Not Allowed (Allow: GET)', $response->getContent());
$this->assertEquals(405, $response->getStatusCode());
$this->assertEquals('GET', $response->headers->get('Allow'));
}
public function testNoErrorHandler()
{
$app = new Application();
......@@ -107,16 +135,21 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
throw new NotFoundHttpException('foo exception');
});
$app->get('/405', function () { return 'foo'; });
$app->error(function ($e, $code) {
return new Response('foo exception handler', $code);
return new Response('foo exception handler');
});
$response = $this->checkRouteResponse($app, '/500', 'foo exception handler');
$this->assertEquals(500, $response->getStatusCode());
$request = Request::create('/404');
$response = $app->handle($request);
$response = $app->handle(Request::create('/404'));
$this->assertEquals(404, $response->getStatusCode());
$response = $app->handle(Request::create('/405', 'POST'));
$this->assertEquals(405, $response->getStatusCode());
$this->assertEquals('GET', $response->headers->get('Allow'));
}
public function testMultipleErrorHandlers()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment