@@ -19,7 +19,7 @@ public function testRender(): void
1919 $ renderer = new JsonRenderer ();
2020 $ data = $ renderer ->render (new RuntimeException ());
2121
22- $ this ->assertSame (json_encode (['message ' => JsonRenderer::DEFAULT_ERROR_MESSAGE ]), (string ) $ data );
22+ $ this ->assertSame (json_encode (['message ' => JsonRenderer::DEFAULT_ERROR_MESSAGE ]), (string )$ data );
2323 }
2424
2525 public function testRenderVerbose (): void
@@ -36,7 +36,7 @@ public function testRenderVerbose(): void
3636 'trace ' => $ throwable ->getTrace (),
3737 ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
3838
39- $ this ->assertSame ($ content , (string ) $ data );
39+ $ this ->assertSame ($ content , (string )$ data );
4040 }
4141
4242 public function testRenderVerboseWithNotUtf8String (): void
@@ -53,6 +53,40 @@ public function testRenderVerboseWithNotUtf8String(): void
5353 'trace ' => $ throwable ->getTrace (),
5454 ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE );
5555
56- $ this ->assertSame ($ content , (string ) $ data );
56+ $ this ->assertSame ($ content , (string )$ data );
57+ }
58+
59+ public function testRenderVerboseWithJsonRecursion (): void
60+ {
61+ $ renderer = new JsonRenderer ();
62+
63+ try {
64+ json_encode (
65+ new class () {
66+ public self $ self ;
67+
68+ public function __construct ()
69+ {
70+ $ this ->self = $ this ;
71+ }
72+ },
73+ JSON_THROW_ON_ERROR
74+ );
75+ } catch (\Throwable $ throwable ) {
76+ $ data = $ renderer ->renderVerbose ($ throwable );
77+ $ content = json_encode (
78+ [
79+ 'type ' => \JsonException::class,
80+ 'message ' => $ throwable ->getMessage (),
81+ 'code ' => $ throwable ->getCode (),
82+ 'file ' => $ throwable ->getFile (),
83+ 'line ' => $ throwable ->getLine (),
84+ 'trace ' => $ throwable ->getTrace (),
85+ ],
86+ JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR
87+ );
88+ }
89+
90+ $ this ->assertSame ($ content , (string )$ data );
5791 }
5892}
0 commit comments