|
12 | 12 | namespace Symfony\Component\ErrorRenderer\Tests\ErrorRenderer;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\ErrorRenderer\ErrorRenderer\ErrorRendererInterface; |
15 | 16 | use Symfony\Component\ErrorRenderer\ErrorRenderer\XmlErrorRenderer;
|
16 | 17 | use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
17 | 18 |
|
18 | 19 | class XmlErrorRendererTest extends TestCase
|
19 | 20 | {
|
20 |
| - public function testRender() |
| 21 | + /** |
| 22 | + * @dataProvider getRenderData |
| 23 | + */ |
| 24 | + public function testRender(FlattenException $exception, ErrorRendererInterface $errorRenderer, string $expected) |
21 | 25 | {
|
22 |
| - $exception = FlattenException::createFromThrowable(new \RuntimeException('Foo')); |
23 |
| - $expected = '<?xml version="1.0" encoding="UTF-8" ?>%A<problem xmlns="urn:ietf:rfc:7807">%A<title>Internal Server Error</title>%A<status>500</status>%A<detail>Foo</detail>%A'; |
| 26 | + $this->assertStringMatchesFormat($expected, $errorRenderer->render($exception)); |
| 27 | + } |
| 28 | + |
| 29 | + public function getRenderData() |
| 30 | + { |
| 31 | + $expectedDebug = <<<XML |
| 32 | +<?xml version="1.0" encoding="UTF-8" ?> |
| 33 | +<problem xmlns="urn:ietf:rfc:7807"> |
| 34 | + <title>Internal Server Error</title> |
| 35 | + <status>500</status> |
| 36 | + <detail>Foo</detail> |
| 37 | + <exceptions><exception class="RuntimeException" message="Foo"><traces><trace>%A</trace></traces></exception></exceptions> |
| 38 | +</problem> |
| 39 | +XML; |
| 40 | + |
| 41 | + $expectedNonDebug = <<<XML |
| 42 | +<?xml version="1.0" encoding="UTF-8" ?> |
| 43 | +<problem xmlns="urn:ietf:rfc:7807"> |
| 44 | + <title>Internal Server Error</title> |
| 45 | + <status>500</status> |
| 46 | + <detail>Foo</detail> |
| 47 | + |
| 48 | +</problem> |
| 49 | +XML; |
| 50 | + |
| 51 | + yield '->render() returns the XML content WITH stack traces in debug mode' => [ |
| 52 | + FlattenException::createFromThrowable(new \RuntimeException('Foo')), |
| 53 | + new XmlErrorRenderer(true), |
| 54 | + $expectedDebug, |
| 55 | + ]; |
| 56 | + |
| 57 | + yield '->render() returns the XML content WITHOUT stack traces in non-debug mode' => [ |
| 58 | + FlattenException::createFromThrowable(new \RuntimeException('Foo')), |
| 59 | + new XmlErrorRenderer(false), |
| 60 | + $expectedNonDebug, |
| 61 | + ]; |
| 62 | + |
| 63 | + yield '->render() returns the XML content WITHOUT stack traces in debug mode FORCING non-debug via X-Debug header' => [ |
| 64 | + FlattenException::createFromThrowable(new \RuntimeException('Foo'), null, ['X-Debug' => false]), |
| 65 | + new XmlErrorRenderer(true), |
| 66 | + $expectedNonDebug, |
| 67 | + ]; |
24 | 68 |
|
25 |
| - $this->assertStringMatchesFormat($expected, (new XmlErrorRenderer(true))->render($exception)); |
| 69 | + yield '->render() returns the XML content WITHOUT stack traces in non-debug mode EVEN FORCING debug via X-Debug header' => [ |
| 70 | + FlattenException::createFromThrowable(new \RuntimeException('Foo'), null, ['X-Debug' => true]), |
| 71 | + new XmlErrorRenderer(false), |
| 72 | + $expectedNonDebug, |
| 73 | + ]; |
26 | 74 | }
|
27 | 75 | }
|
0 commit comments