Commit a03ee092 authored by Fabien Potencier's avatar Fabien Potencier

Merge remote branch 'igorw/beforefilter-httpexception'

* igorw/beforefilter-httpexception:
  [Application] onSilexBefore should fire on BaseHttpException
parents 14487c1f f508a0e3
......@@ -286,6 +286,8 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
'is_secure' => $this['request']->isSecure(),
));
$this['dispatcher']->dispatch(Events::onSilexBefore);
try {
$attributes = $matcher->match($this['request']->getPathInfo());
......@@ -297,8 +299,6 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $this['request']->getMethod(), $this['request']->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
throw new MethodNotAllowedHttpException($e->getAllowedMethods(), 'Method Not Allowed', $message, 0, $e);
}
$this['dispatcher']->dispatch(Events::onSilexBefore);
}
/**
......
......@@ -15,6 +15,7 @@ use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Error handler test cases.
......@@ -26,7 +27,6 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
public function testBeforeAndAfterFilter()
{
$i = 0;
$test = $this;
$application = new Application();
......@@ -76,7 +76,6 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
public function testMultipleFilters()
{
$i = 0;
$test = $this;
$application = new Application();
......@@ -111,4 +110,56 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(5, $i);
}
public function testFiltersShouldFireOnException()
{
$i = 0;
$application = new Application();
$application->before(function() use(&$i) {
$i++;
});
$application->match('/foo', function() {
throw new \RuntimeException();
});
$application->after(function() use(&$i) {
$i++;
});
$application->error(function() {
return 'error handled';
});
$request = Request::create('/foo');
$application->handle($request);
$this->assertEquals(2, $i);
}
public function testFiltersShouldFireOnHttpException()
{
$i = 0;
$application = new Application();
$application->before(function() use(&$i) {
$i++;
});
$application->after(function() use(&$i) {
$i++;
});
$application->error(function() {
return 'error handled';
});
$request = Request::create('/nowhere');
$application->handle($request);
$this->assertEquals(2, $i);
}
}
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