SerializerErrorRendererTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Component\ErrorHandler\Tests\ErrorRenderer;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\ErrorHandler\ErrorRenderer\SerializerErrorRenderer;
  13. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  14. use Symfony\Component\Serializer\Normalizer\ProblemNormalizer;
  15. use Symfony\Component\Serializer\Serializer;
  16. class SerializerErrorRendererTest extends TestCase
  17. {
  18. public function testDefaultContent()
  19. {
  20. $errorRenderer = new SerializerErrorRenderer(new Serializer(), 'html');
  21. self::assertStringContainsString('<h2>The server returned a "500 Internal Server Error".</h2>', $errorRenderer->render(new \RuntimeException())->getAsString());
  22. }
  23. public function testSerializerContent()
  24. {
  25. $exception = new \RuntimeException('Foo');
  26. $errorRenderer = new SerializerErrorRenderer(
  27. new Serializer([new ProblemNormalizer()], [new JsonEncoder()]),
  28. function () { return 'json'; }
  29. );
  30. $this->assertSame('{"type":"https:\/\/tools.ietf.org\/html\/rfc2616#section-10","title":"An error occurred","status":500,"detail":"Internal Server Error"}', $errorRenderer->render($exception)->getAsString());
  31. }
  32. }