FlattenExceptionTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\HttpKernel\Exception;
  11. use Symfony\Component\HttpKernel\Exception\FlattenException;
  12. class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider flattenDataProvider
  16. */
  17. public function testFlattenHttpException(\Exception $exception, $statusCode)
  18. {
  19. $flattened = FlattenException::create($exception);
  20. $this->assertEquals($statusCode, $flattened->getStatusCode(), 'A HttpKernel exception uses the error code as the status code.');
  21. $this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
  22. $this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
  23. $this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception');
  24. }
  25. public function flattenDataProvider()
  26. {
  27. return array(
  28. array(new TestHttpException('test', 404), 404),
  29. array(new \Exception('test', 123), 500),
  30. );
  31. }
  32. }
  33. use Symfony\Component\HttpKernel\Exception\HttpException;
  34. // stub Exception class that extends HttpException
  35. class TestHttpException extends HttpException
  36. {
  37. }