Commit d230b294 authored by Fabien Potencier's avatar Fabien Potencier

merged branch igorw/request-scope-error (PR #263)

Commits
-------

c78353e2 Give useful error message when accessing request outside of request scope

Discussion
----------

Give useful error message when accessing request outside of request scope
parents 219ba070 c78353e2
...@@ -111,6 +111,10 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe ...@@ -111,6 +111,10 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return new RedirectableUrlMatcher($app['routes'], $app['request_context']); return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
}); });
$this['request'] = function () {
throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.');
};
$this['request.http_port'] = 80; $this['request.http_port'] = 80;
$this['request.https_port'] = 443; $this['request.https_port'] = 443;
$this['debug'] = false; $this['debug'] = false;
......
...@@ -58,7 +58,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase ...@@ -58,7 +58,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($request, $app['request']); $this->assertEquals($request, $app['request']);
} }
public function testgetRoutesWithNoRoutes() public function testGetRoutesWithNoRoutes()
{ {
$app = new Application(); $app = new Application();
...@@ -165,6 +165,16 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase ...@@ -165,6 +165,16 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('text/html; charset=ISO-8859-1', $response->headers->get('Content-Type')); $this->assertEquals('text/html; charset=ISO-8859-1', $response->headers->get('Content-Type'));
} }
/**
* @expectedException RuntimeException
*/
public function testAccessingRequestOutsideOfScopeShouldThrowRuntimeException()
{
$app = new Application();
$request = $app['request'];
}
} }
class FooController class FooController
......
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