mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-11 05:48:51 +00:00
[feature/controller] Fix comments, check against more general HttpException
PHPBB3-10864
This commit is contained in:
parent
f8614bfc84
commit
01ec608593
2 changed files with 6 additions and 5 deletions
|
@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterface
|
class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterface
|
||||||
|
@ -71,7 +71,7 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac
|
||||||
page_footer(true, false, false);
|
page_footer(true, false, false);
|
||||||
|
|
||||||
|
|
||||||
$status_code = $exception instanceof NotFoundHttpException ? $exception->getStatusCode() : 500;
|
$status_code = $exception instanceof HttpException ? $exception->getStatusCode() : 500;
|
||||||
$response = new Response($this->template->assign_display('body'), $status_code);
|
$response = new Response($this->template->assign_display('body'), $status_code);
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
$this->phpbb_extension_manager->purge('foo/bar');
|
$this->phpbb_extension_manager->purge('foo/bar');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_exception_thrown_status_code()
|
/**
|
||||||
|
* Check the status code resulting from an exception thrown by a controller
|
||||||
|
*/
|
||||||
|
public function test_exception_should_result_in_500_status_code()
|
||||||
{
|
{
|
||||||
$this->phpbb_extension_manager->enable('foo/bar');
|
$this->phpbb_extension_manager->enable('foo/bar');
|
||||||
$crawler = $this->request('GET', 'app.php?controller=foo/exception');
|
$crawler = $this->request('GET', 'app.php?controller=foo/exception');
|
||||||
|
@ -142,8 +145,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
public function test_error_ext_disabled_or_404()
|
public function test_error_ext_disabled_or_404()
|
||||||
{
|
{
|
||||||
$crawler = $this->request('GET', 'app.php?controller=does/not/exist');
|
$crawler = $this->request('GET', 'app.php?controller=does/not/exist');
|
||||||
// This is 500 response because the exception is thrown from within Symfony
|
|
||||||
// and does not provide a exception code, so we assign it 500 by default
|
|
||||||
$this->assertEquals(404, $this->client->getResponse()->getStatus());
|
$this->assertEquals(404, $this->client->getResponse()->getStatus());
|
||||||
$this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
|
$this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue