|
10 | 10 |
|
11 | 11 | namespace Symfony\Component\Serializer\Tests\ErrorRenderer;
|
12 | 12 |
|
| 13 | +use function json_decode; |
13 | 14 | use PHPUnit\Framework\TestCase;
|
14 | 15 | use Symfony\Component\ErrorHandler\ErrorRenderer\SerializerErrorRenderer;
|
15 |
| -use Symfony\Component\Serializer\Serializer; |
16 | 16 | use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
17 | 17 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
18 |
| - |
19 |
| -use function \json_decode; |
| 18 | +use Symfony\Component\Serializer\Serializer; |
20 | 19 |
|
21 | 20 | /**
|
22 | 21 | * @author Alexey Deriyenko <alexey.deriyenko@gmail.com>
|
23 | 22 | */
|
24 |
| -class SerializerErrorRendererTest extends TestCase { |
| 23 | +class SerializerErrorRendererTest extends TestCase |
| 24 | +{ |
25 | 25 | /**
|
26 | 26 | * @dataProvider getRenderData
|
27 | 27 | */
|
28 |
| - public function testRenderReturnsJson(\Throwable $exception, SerializerErrorRenderer $serializerErrorRenderer) { |
| 28 | + public function testRenderReturnsJson(\Throwable $exception, SerializerErrorRenderer $serializerErrorRenderer) |
| 29 | + { |
29 | 30 | $this->assertJson($serializerErrorRenderer->render($exception)->getAsString());
|
30 | 31 | }
|
31 | 32 |
|
32 | 33 | /**
|
33 | 34 | * @dataProvider getRenderData
|
34 | 35 | */
|
35 |
| - public function testRenderReturnsJsonWithCorrectStatusCode(\Throwable $exception, SerializerErrorRenderer $serializerErrorRenderer, int $expectedStatusCode) { |
| 36 | + public function testRenderReturnsJsonWithCorrectStatusCode(\Throwable $exception, SerializerErrorRenderer $serializerErrorRenderer, int $expectedStatusCode) |
| 37 | + { |
36 | 38 | $statusCodeFromJson = json_decode($serializerErrorRenderer->render($exception)->getAsString())->statusCode;
|
37 | 39 | $this->assertEquals($expectedStatusCode, $statusCodeFromJson);
|
38 | 40 | }
|
39 | 41 |
|
40 | 42 | /**
|
41 | 43 | * @dataProvider getRenderData
|
42 | 44 | */
|
43 |
| - public function testRenderReturnsJsonWithCorrectStatusText(\Throwable $exception, SerializerErrorRenderer $serializerErrorRenderer, int $expectedStatusCode, string $expectedStatusText) { |
| 45 | + public function testRenderReturnsJsonWithCorrectStatusText(\Throwable $exception, SerializerErrorRenderer $serializerErrorRenderer, int $expectedStatusCode, string $expectedStatusText) |
| 46 | + { |
44 | 47 | $statusTextFromJson = json_decode($serializerErrorRenderer->render($exception)->getAsString())->statusText;
|
45 | 48 | $this->assertEquals($expectedStatusText, $statusTextFromJson);
|
46 | 49 | }
|
47 | 50 |
|
48 |
| - public function getRenderData(): iterable { |
| 51 | + public function getRenderData(): iterable |
| 52 | + { |
49 | 53 | yield '->render() returns the JSON content WITH stack traces in debug mode' => [
|
50 | 54 | new \RuntimeException('Foo'),
|
51 | 55 | new SerializerErrorRenderer(new Serializer([new ObjectNormalizer()], [new JsonEncoder()]), 'json', null, true),
|
52 | 56 | 500,
|
53 |
| - 'Internal Server Error' |
| 57 | + 'Internal Server Error', |
54 | 58 | ];
|
55 | 59 |
|
56 | 60 | yield '->render() returns the JSON content WITHOUT stack traces in non-debug mode' => [
|
57 | 61 | new \RuntimeException('Foo'),
|
58 | 62 | new SerializerErrorRenderer(new Serializer([new ObjectNormalizer()], [new JsonEncoder()]), 'json', null, false),
|
59 | 63 | 500,
|
60 |
| - 'Internal Server Error' |
| 64 | + 'Internal Server Error', |
61 | 65 | ];
|
62 | 66 |
|
63 | 67 | yield '->render() returns the JSON content WITH stack traces in debug mode and contains the correct status code' => [
|
64 | 68 | new \RuntimeException('Foo'),
|
65 | 69 | new SerializerErrorRenderer(new Serializer([new ObjectNormalizer()], [new JsonEncoder()]), 'json', null, true, [
|
66 | 70 | \RuntimeException::class => [
|
67 | 71 | 'status_code' => 418,
|
68 |
| - 'log_level' => null, |
| 72 | + 'log_level' => null, |
69 | 73 | ],
|
70 | 74 | ]),
|
71 | 75 | 418,
|
72 |
| - 'I\'m a teapot' |
| 76 | + 'I\'m a teapot', |
73 | 77 | ];
|
74 | 78 |
|
75 | 79 | yield '->render() returns the JSON content WITHOUT stack traces in non-debug mode and contains the correct status code' => [
|
76 | 80 | new \RuntimeException('Foo'),
|
77 | 81 | new SerializerErrorRenderer(new Serializer([new ObjectNormalizer()], [new JsonEncoder()]), 'json', null, true, [
|
78 | 82 | \RuntimeException::class => [
|
79 | 83 | 'status_code' => 418,
|
80 |
| - 'log_level' => null, |
| 84 | + 'log_level' => null, |
81 | 85 | ],
|
82 | 86 | ]),
|
83 | 87 | 418,
|
84 |
| - 'I\'m a teapot' |
| 88 | + 'I\'m a teapot', |
85 | 89 | ];
|
86 | 90 | }
|
87 | 91 | }
|
0 commit comments