21
21
class PhpDebugBarMiddlewareTest extends TestCase
22
22
{
23
23
protected $ debugbarRenderer ;
24
+ /** @var PhpDebugBarMiddleware */
24
25
protected $ middleware ;
25
26
26
27
protected function setUp ()
@@ -76,6 +77,7 @@ public function testForceAttachDebugbarIfHeaderPresents(): void
76
77
77
78
$ result = $ this ->middleware ->process ($ request , $ requestHandler );
78
79
80
+ $ this ->assertSame (200 , $ result ->getStatusCode ());
79
81
$ this ->assertSame ("<html><head>RenderHead</head><body><h1>DebugBar</h1><p>Response:</p><pre>HTTP/1.1 200 OK \r\n\r\nResponseBody</pre>RenderBody</body></html> " , (string ) $ result ->getBody ());
80
82
}
81
83
@@ -108,7 +110,7 @@ public function testForceAttachDebugbarIfAttributePresents(): void
108
110
public function testAttachToNoneHtmlResponse (): void
109
111
{
110
112
$ request = new ServerRequest ([], [], null , null , 'php://input ' , ['Accept ' => 'text/html ' ]);
111
- $ response = new Response ();
113
+ $ response = ( new Response ())-> withHeader ( ' test-header ' , ' value ' );
112
114
$ response ->getBody ()->write ('ResponseBody ' );
113
115
114
116
$ requestHandler = new RequestHandlerStub ($ response );
@@ -117,22 +119,45 @@ public function testAttachToNoneHtmlResponse(): void
117
119
118
120
$ this ->assertTrue ($ requestHandler ->isCalled (), 'Request handler is not called ' );
119
121
$ this ->assertNotSame ($ response , $ result );
120
- $ this ->assertSame ("<html><head>RenderHead</head><body><h1>DebugBar</h1><p>Response:</p><pre>HTTP/1.1 200 OK \r\n\r\nResponseBody</pre>RenderBody</body></html> " , (string ) $ result ->getBody ());
122
+ $ this ->assertSame ("<html><head>RenderHead</head><body><h1>DebugBar</h1><p>Response:</p><pre>HTTP/1.1 200 OK \r\n Test-Header: value \r\ n\r\nResponseBody</pre>RenderBody</body></html> " , (string ) $ result ->getBody ());
121
123
}
122
124
123
125
public function testNotAttachToRedirectResponse (): void
124
126
{
125
127
$ request = new ServerRequest ([], [], null , null , 'php://input ' , ['Accept ' => 'text/html ' ]);
126
- $ response = (new Response ())->withStatus (302 )->withAddedHeader ('Location ' , 'some-location ' );
128
+ $ response = (new Response ())->withStatus (300 )->withAddedHeader ('Location ' , 'some-location ' );
127
129
128
130
$ requestHandler = new RequestHandlerStub ($ response );
129
131
130
132
$ result = $ this ->middleware ->process ($ request , $ requestHandler );
131
133
132
- $ this ->assertTrue ($ requestHandler ->isCalled (), 'Request handler is not called ' );
133
134
$ this ->assertSame ($ response , $ result );
134
135
}
135
136
137
+ public function testAttachToNonRedirectResponse (): void
138
+ {
139
+ $ request = new ServerRequest ([], [], null , null , 'php://input ' , ['Accept ' => 'text/html ' ]);
140
+ $ response = (new Response ())->withStatus (299 )->withAddedHeader ('Location ' , 'some-location ' );
141
+
142
+ $ requestHandler = new RequestHandlerStub ($ response );
143
+
144
+ $ result = $ this ->middleware ->process ($ request , $ requestHandler );
145
+
146
+ $ this ->assertNotSame ($ response , $ result );
147
+ }
148
+
149
+ public function testAttachToNonRedirectResponse2 (): void
150
+ {
151
+ $ request = new ServerRequest ([], [], null , null , 'php://input ' , ['Accept ' => 'text/html ' ]);
152
+ $ response = (new Response ())->withStatus (400 )->withAddedHeader ('Location ' , 'some-location ' );
153
+
154
+ $ requestHandler = new RequestHandlerStub ($ response );
155
+
156
+ $ result = $ this ->middleware ->process ($ request , $ requestHandler );
157
+
158
+ $ this ->assertNotSame ($ response , $ result );
159
+ }
160
+
136
161
public function testAttachToRedirectResponseWithoutLocation (): void
137
162
{
138
163
$ request = new ServerRequest ([], [], null , null , 'php://input ' , ['Accept ' => 'text/html ' ]);
@@ -268,6 +293,7 @@ public function testHandleStaticFile(string $extension, string $contentType): vo
268
293
$ this ->assertFalse ($ requestHandler ->isCalled (), 'Request handler is called ' );
269
294
$ this ->assertNotSame ($ response , $ result );
270
295
$ this ->assertSame ($ contentType , $ result ->getHeaderLine ('Content-type ' ));
296
+ $ this ->assertSame (200 , $ result ->getStatusCode ());
271
297
$ this ->assertSame ('filecontent ' , (string ) $ result ->getBody ());
272
298
}
273
299
0 commit comments