@@ -25,25 +25,37 @@ final class ErrorCatcherTest extends TestCase
2525{
2626 public function testProcessWithHeadRequestMethod (): void
2727 {
28- $ response = $ this ->createErrorCatcher ()->process (
29- $ this ->createServerRequest ('HEAD ' , ['Accept ' => ['test/html ' ]]),
30- $ this ->createRequestHandlerWithThrowable (),
31- );
32- $ response ->getBody ()->rewind ();
33- $ content = $ response ->getBody ()->getContents ();
28+ $ response = $ this
29+ ->createErrorCatcher ()
30+ ->process (
31+ $ this ->createServerRequest ('HEAD ' , ['Accept ' => ['test/html ' ]]),
32+ $ this ->createRequestHandlerWithThrowable (),
33+ );
34+ $ response
35+ ->getBody ()
36+ ->rewind ();
37+ $ content = $ response
38+ ->getBody ()
39+ ->getContents ();
3440
3541 $ this ->assertEmpty ($ content );
3642 $ this ->assertSame ([HeaderRenderer::DEFAULT_ERROR_MESSAGE ], $ response ->getHeader ('X-Error-Message ' ));
3743 }
3844
3945 public function testProcessWithFailAcceptRequestHeader (): void
4046 {
41- $ response = $ this ->createErrorCatcher ()->process (
42- $ this ->createServerRequest ('GET ' , ['Accept ' => ['text/plain;q=2.0 ' ]]),
43- $ this ->createRequestHandlerWithThrowable (),
44- );
45- $ response ->getBody ()->rewind ();
46- $ content = $ response ->getBody ()->getContents ();
47+ $ response = $ this
48+ ->createErrorCatcher ()
49+ ->process (
50+ $ this ->createServerRequest ('GET ' , ['Accept ' => ['text/plain;q=2.0 ' ]]),
51+ $ this ->createRequestHandlerWithThrowable (),
52+ );
53+ $ response
54+ ->getBody ()
55+ ->rewind ();
56+ $ content = $ response
57+ ->getBody ()
58+ ->getContents ();
4759
4860 $ this ->assertNotSame (PlainTextRenderer::DEFAULT_ERROR_MESSAGE , $ content );
4961 $ this ->assertStringContainsString ('<html ' , $ content );
@@ -52,13 +64,19 @@ public function testProcessWithFailAcceptRequestHeader(): void
5264 public function testAddedRenderer (): void
5365 {
5466 $ mimeType = 'test/test ' ;
55- $ catcher = $ this ->createErrorCatcher ()->withRenderer ($ mimeType , PlainTextRenderer::class);
67+ $ catcher = $ this
68+ ->createErrorCatcher ()
69+ ->withRenderer ($ mimeType , PlainTextRenderer::class);
5670 $ response = $ catcher ->process (
5771 $ this ->createServerRequest ('GET ' , ['Accept ' => [$ mimeType ]]),
5872 $ this ->createRequestHandlerWithThrowable (),
5973 );
60- $ response ->getBody ()->rewind ();
61- $ content = $ response ->getBody ()->getContents ();
74+ $ response
75+ ->getBody ()
76+ ->rewind ();
77+ $ content = $ response
78+ ->getBody ()
79+ ->getContents ();
6280
6381 $ this ->assertSame (PlainTextRenderer::DEFAULT_ERROR_MESSAGE , $ content );
6482 }
@@ -69,77 +87,109 @@ public function testThrownExceptionWithRendererIsNotImplementThrowableRendererIn
6987 $ this ->expectErrorMessage (
7088 'Class " ' . self ::class . '" does not implement " ' . ThrowableRendererInterface::class . '". ' ,
7189 );
72- $ this ->createErrorCatcher ()->withRenderer ('test/test ' , self ::class);
90+ $ this
91+ ->createErrorCatcher ()
92+ ->withRenderer ('test/test ' , self ::class);
7393 }
7494
7595 public function testThrownExceptionWithInvalidContentType ()
7696 {
7797 $ this ->expectException (InvalidArgumentException::class);
7898 $ this ->expectErrorMessage ('Invalid content type. ' );
79- $ this ->createErrorCatcher ()->withRenderer ('test invalid content type ' , PlainTextRenderer::class);
99+ $ this
100+ ->createErrorCatcher ()
101+ ->withRenderer ('test invalid content type ' , PlainTextRenderer::class);
80102 }
81103
82104 public function testWithoutRenderers (): void
83105 {
84- $ catcher = $ this ->createErrorCatcher ()->withoutRenderers ();
106+ $ catcher = $ this
107+ ->createErrorCatcher ()
108+ ->withoutRenderers ();
85109 $ response = $ catcher ->process (
86110 $ this ->createServerRequest ('GET ' , ['Accept ' => ['test/html ' ]]),
87111 $ this ->createRequestHandlerWithThrowable (),
88112 );
89- $ response ->getBody ()->rewind ();
90- $ content = $ response ->getBody ()->getContents ();
113+ $ response
114+ ->getBody ()
115+ ->rewind ();
116+ $ content = $ response
117+ ->getBody ()
118+ ->getContents ();
91119
92120 $ this ->assertSame (PlainTextRenderer::DEFAULT_ERROR_MESSAGE , $ content );
93121 }
94122
95123 public function testWithoutRenderer (): void
96124 {
97- $ catcher = $ this ->createErrorCatcher ()->withoutRenderers ('*/* ' );
125+ $ catcher = $ this
126+ ->createErrorCatcher ()
127+ ->withoutRenderers ('*/* ' );
98128 $ response = $ catcher ->process (
99129 $ this ->createServerRequest ('GET ' , ['Accept ' => ['test/html ' ]]),
100130 $ this ->createRequestHandlerWithThrowable (),
101131 );
102- $ response ->getBody ()->rewind ();
103- $ content = $ response ->getBody ()->getContents ();
132+ $ response
133+ ->getBody ()
134+ ->rewind ();
135+ $ content = $ response
136+ ->getBody ()
137+ ->getContents ();
104138
105139 $ this ->assertSame (PlainTextRenderer::DEFAULT_ERROR_MESSAGE , $ content );
106140 }
107141
108142 public function testAdvancedAcceptHeader (): void
109143 {
110144 $ contentType = 'text/html;version=2 ' ;
111- $ catcher = $ this ->createErrorCatcher ()->withRenderer ($ contentType , PlainTextRenderer::class);
145+ $ catcher = $ this
146+ ->createErrorCatcher ()
147+ ->withRenderer ($ contentType , PlainTextRenderer::class);
112148 $ response = $ catcher ->process (
113149 $ this ->createServerRequest ('GET ' , ['Accept ' => ['text/html ' , $ contentType ]]),
114150 $ this ->createRequestHandlerWithThrowable (),
115151 );
116- $ response ->getBody ()->rewind ();
117- $ content = $ response ->getBody ()->getContents ();
152+ $ response
153+ ->getBody ()
154+ ->rewind ();
155+ $ content = $ response
156+ ->getBody ()
157+ ->getContents ();
118158
119159 $ this ->assertSame (PlainTextRenderer::DEFAULT_ERROR_MESSAGE , $ content );
120160 }
121161
122162 public function testDefaultContentType (): void
123163 {
124- $ catcher = $ this ->createErrorCatcher ()->withRenderer ('*/* ' , PlainTextRenderer::class);
164+ $ catcher = $ this
165+ ->createErrorCatcher ()
166+ ->withRenderer ('*/* ' , PlainTextRenderer::class);
125167 $ response = $ catcher ->process (
126168 $ this ->createServerRequest ('GET ' , ['Accept ' => ['test/test ' ]]),
127169 $ this ->createRequestHandlerWithThrowable (),
128170 );
129- $ response ->getBody ()->rewind ();
130- $ content = $ response ->getBody ()->getContents ();
171+ $ response
172+ ->getBody ()
173+ ->rewind ();
174+ $ content = $ response
175+ ->getBody ()
176+ ->getContents ();
131177
132178 $ this ->assertSame (PlainTextRenderer::DEFAULT_ERROR_MESSAGE , $ content );
133179 }
134180
135181 public function testForceContentType (): void
136182 {
137- $ catcher = $ this ->createErrorCatcher ()->forceContentType ('application/json ' );
183+ $ catcher = $ this
184+ ->createErrorCatcher ()
185+ ->forceContentType ('application/json ' );
138186 $ response = $ catcher ->process (
139187 $ this ->createServerRequest ('GET ' , ['Accept ' => ['text/xml ' ]]),
140188 $ this ->createRequestHandlerWithThrowable (),
141189 );
142- $ response ->getBody ()->rewind ();
190+ $ response
191+ ->getBody ()
192+ ->rewind ();
143193
144194 $ this ->assertSame ('application/json ' , $ response ->getHeaderLine (Header::CONTENT_TYPE ));
145195 }
@@ -148,7 +198,9 @@ public function testForceContentTypeSetInvalidType(): void
148198 {
149199 $ this ->expectException (InvalidArgumentException::class);
150200 $ this ->expectErrorMessage ('The renderer for image/gif is not set. ' );
151- $ this ->createErrorCatcher ()->forceContentType ('image/gif ' );
201+ $ this
202+ ->createErrorCatcher ()
203+ ->forceContentType ('image/gif ' );
152204 }
153205
154206 private function createErrorHandler (): ErrorHandler
0 commit comments