diff --git a/src/Symfony/Component/HttpKernel/Exception/ForbiddenHttpException.php b/src/Symfony/Component/HttpKernel/Exception/ForbiddenHttpException.php index 933140894c..40d9f471a9 100644 --- a/src/Symfony/Component/HttpKernel/Exception/ForbiddenHttpException.php +++ b/src/Symfony/Component/HttpKernel/Exception/ForbiddenHttpException.php @@ -18,7 +18,7 @@ namespace Symfony\Component\HttpKernel\Exception; */ class ForbiddenHttpException extends HttpException { - public function __construct($message = '', $code = 0, \Exception $previous = null) + public function __construct($message = '', \Exception $previous = null) { if (!$message) { $message = 'Forbidden'; diff --git a/src/Symfony/Component/HttpKernel/Exception/HttpException.php b/src/Symfony/Component/HttpKernel/Exception/HttpException.php index 8c54c74b4e..99fb80b036 100644 --- a/src/Symfony/Component/HttpKernel/Exception/HttpException.php +++ b/src/Symfony/Component/HttpKernel/Exception/HttpException.php @@ -20,4 +20,13 @@ namespace Symfony\Component\HttpKernel\Exception; */ class HttpException extends \Exception { + /** + * Constructor overridden to require the code, which is the status code. + * + * @see \Exception + */ + public function __construct($message, $code, \Exception $previous = null) + { + parent::__construct($message, $code, $previous); + } } diff --git a/src/Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php b/src/Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php index 52e43bbaa9..4a4c048717 100644 --- a/src/Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php +++ b/src/Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php @@ -18,7 +18,7 @@ namespace Symfony\Component\HttpKernel\Exception; */ class NotFoundHttpException extends HttpException { - public function __construct($message = '', $code = 0, \Exception $previous = null) + public function __construct($message = '', \Exception $previous = null) { if (!$message) { $message = 'Not Found'; diff --git a/src/Symfony/Component/HttpKernel/Exception/UnauthorizedHttpException.php b/src/Symfony/Component/HttpKernel/Exception/UnauthorizedHttpException.php index 26c4a4167c..7f6623c74c 100644 --- a/src/Symfony/Component/HttpKernel/Exception/UnauthorizedHttpException.php +++ b/src/Symfony/Component/HttpKernel/Exception/UnauthorizedHttpException.php @@ -18,7 +18,7 @@ namespace Symfony\Component\HttpKernel\Exception; */ class UnauthorizedHttpException extends HttpException { - public function __construct($message = '', $code = 0, \Exception $previous = null) + public function __construct($message = '', \Exception $previous = null) { if (!$message) { $message = 'Unauthorized'; diff --git a/tests/Symfony/Tests/Component/HttpKernel/Exception/FlattenExceptionTest.php b/tests/Symfony/Tests/Component/HttpKernel/Exception/FlattenExceptionTest.php new file mode 100644 index 0000000000..67b39d585d --- /dev/null +++ b/tests/Symfony/Tests/Component/HttpKernel/Exception/FlattenExceptionTest.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\HttpKernel\Exception; +use Symfony\Component\HttpKernel\Exception\FlattenException; + +class FlattenExceptionTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider flattenDataProvider + */ + public function testFlattenHttpException(\Exception $exception, $statusCode) + { + $flattened = FlattenException::create($exception); + + $this->assertEquals($statusCode, $flattened->getStatusCode(), 'A HttpKernel exception uses the error code as the status code.'); + $this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.'); + $this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.'); + $this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception'); + + } + + public function flattenDataProvider() + { + return array( + array(new TestHttpException('test', 404), 404), + array(new \Exception('test', 123), 500), + ); + } +} + +use Symfony\Component\HttpKernel\Exception\HttpException; + +// stub Exception class that extends HttpException +class TestHttpException extends HttpException +{ +} \ No newline at end of file