99use Laravel \Octane \RequestContext ;
1010use Laravel \Octane \Swoole \SwooleClient ;
1111use Mockery ;
12+ use Swoole \Http \Response as SwooleResponse ;
1213use Symfony \Component \HttpFoundation \StreamedResponse ;
1314
1415class SwooleClientTest extends TestCase
1516{
16- public function test_marshal_request_method_marshals_proper_illuminate_request ()
17+ public function test_marshal_request_method_marshals_proper_illuminate_request (): void
1718 {
1819 $ client = new SwooleClient ;
1920
@@ -57,7 +58,7 @@ public function rawContent()
5758 $ this ->assertSame ($ givenContext , $ context );
5859 }
5960
60- public function test_can_serve_static_files_if_configured_to_and_file_is_within_public_directory ()
61+ public function test_can_serve_static_files_if_configured_to_and_file_is_within_public_directory (): void
6162 {
6263 $ client = new SwooleClient ;
6364
@@ -71,7 +72,7 @@ public function test_can_serve_static_files_if_configured_to_and_file_is_within_
7172 $ this ->assertTrue ($ client ->canServeRequestAsStaticFile ($ request , $ context ));
7273 }
7374
74- public function test_cant_serve_static_files_if_file_is_outside_public_directory ()
75+ public function test_cant_serve_static_files_if_file_is_outside_public_directory (): void
7576 {
7677 $ client = new SwooleClient ;
7778
@@ -85,7 +86,7 @@ public function test_cant_serve_static_files_if_file_is_outside_public_directory
8586 $ this ->assertFalse ($ client ->canServeRequestAsStaticFile ($ request , $ context ));
8687 }
8788
88- public function test_cant_serve_static_files_if_file_has_forbidden_extension ()
89+ public function test_cant_serve_static_files_if_file_has_forbidden_extension (): void
8990 {
9091 $ client = new SwooleClient ;
9192
@@ -100,7 +101,7 @@ public function test_cant_serve_static_files_if_file_has_forbidden_extension()
100101 }
101102
102103 /** @doesNotPerformAssertions @test */
103- public function test_static_file_can_be_served ()
104+ public function test_static_file_can_be_served (): void
104105 {
105106 $ client = new SwooleClient ;
106107
@@ -119,7 +120,8 @@ public function test_static_file_can_be_served()
119120 $ client ->serveStaticFile ($ request , $ context );
120121 }
121122
122- public function test_static_file_headers_can_be_sent ()
123+ /** @doesNotPerformAssertions @test */
124+ public function test_static_file_headers_can_be_sent (): void
123125 {
124126 $ client = new SwooleClient ;
125127
@@ -147,7 +149,7 @@ public function test_static_file_headers_can_be_sent()
147149 $ this ->assertTrue (true );
148150 }
149151
150- public function test_can_serve_static_files_through_symlink ()
152+ public function test_can_serve_static_files_through_symlink (): void
151153 {
152154 $ client = new SwooleClient ;
153155
@@ -161,7 +163,7 @@ public function test_can_serve_static_files_through_symlink()
161163 $ this ->assertTrue ($ client ->canServeRequestAsStaticFile ($ request , $ context ));
162164 }
163165
164- public function test_cant_serve_static_files_through_symlink_using_directory_traversal ()
166+ public function test_cant_serve_static_files_through_symlink_using_directory_traversal (): void
165167 {
166168 $ client = new SwooleClient ;
167169
@@ -176,13 +178,11 @@ public function test_cant_serve_static_files_through_symlink_using_directory_tra
176178 }
177179
178180 /** @doesNotPerformAssertions @test */
179- public function test_respond_method_sends_response_to_swoole ()
181+ public function test_respond_method_sends_response_to_swoole (): void
180182 {
181- $ client = new SwooleClient ;
183+ $ this -> createApplication () ;
182184
183- if (extension_loaded ('openswoole ' )) {
184- $ this ->markTestSkipped ('This test is not compatible with Open Swoole ' );
185- }
185+ $ client = new SwooleClient ;
186186
187187 $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
188188
@@ -205,14 +205,10 @@ public function test_respond_method_sends_response_to_swoole()
205205 }
206206
207207 /** @doesNotPerformAssertions @test */
208- public function test_respond_method_send_streamed_response_to_swoole ()
208+ public function test_respond_method_send_streamed_response_to_swoole (): void
209209 {
210210 $ client = new SwooleClient ;
211211
212- if (extension_loaded ('openswoole ' )) {
213- $ this ->markTestSkipped ('This test is not compatible with Open Swoole ' );
214- }
215-
216212 $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
217213
218214 $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
@@ -230,14 +226,10 @@ public function test_respond_method_send_streamed_response_to_swoole()
230226 }
231227
232228 /** @doesNotPerformAssertions @test */
233- public function test_respond_method_with_laravel_specific_status_code_sends_response_to_swoole ()
229+ public function test_respond_method_with_laravel_specific_status_code_sends_response_to_swoole (): void
234230 {
235231 $ client = new SwooleClient ;
236232
237- if (extension_loaded ('openswoole ' )) {
238- $ this ->markTestSkipped ('This test is not compatible with Open Swoole ' );
239- }
240-
241233 $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
242234
243235 $ swooleResponse ->shouldReceive ('status ' )->once ()->with (419 , 'Page Expired ' );
@@ -253,14 +245,10 @@ public function test_respond_method_with_laravel_specific_status_code_sends_resp
253245 }
254246
255247 /** @doesNotPerformAssertions @test */
256- public function test_error_method_sends_error_response_to_swoole ()
248+ public function test_error_method_sends_error_response_to_swoole (): void
257249 {
258250 $ client = new SwooleClient ;
259251
260- if (extension_loaded ('openswoole ' )) {
261- $ this ->markTestSkipped ('This test is not compatible with Open Swoole ' );
262- }
263-
264252 $ swooleResponse = Mockery::spy ('Swoole\Http\Response ' );
265253
266254 $ app = $ this ->createApplication ();
@@ -277,14 +265,10 @@ public function test_error_method_sends_error_response_to_swoole()
277265 }
278266
279267 /** @doesNotPerformAssertions @test */
280- public function test_error_method_sends_detailed_error_response_to_swoole_in_debug_mode ()
268+ public function test_error_method_sends_detailed_error_response_to_swoole_in_debug_mode (): void
281269 {
282270 $ client = new SwooleClient ;
283271
284- if (extension_loaded ('openswoole ' )) {
285- $ this ->markTestSkipped ('This test is not compatible with Open Swoole ' );
286- }
287-
288272 $ swooleResponse = Mockery::spy ('Swoole\Http\Response ' );
289273
290274 $ app = $ this ->createApplication ();
@@ -299,4 +283,47 @@ public function test_error_method_sends_detailed_error_response_to_swoole_in_deb
299283 $ swooleResponse ->shouldHaveReceived ('header ' )->with ('Content-Type ' , 'text/plain ' );
300284 $ swooleResponse ->shouldHaveReceived ('end ' )->with ((string ) $ e );
301285 }
286+
287+ /** @doesNotPerformAssertions @test */
288+ public function test_respond_method_send_not_chunked_response_to_swoole (): void
289+ {
290+ $ client = new SwooleClient ;
291+
292+ $ swooleResponse = Mockery::mock (SwooleResponse::class);
293+
294+ $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
295+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' );
296+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' );
297+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ));
298+ $ swooleResponse ->shouldReceive ('write ' )->never ();
299+ $ swooleResponse ->shouldReceive ('end ' )->once ()->with ('Hello World ' );
300+
301+ $ response = new Response ('Hello World ' , 200 , ['Content-Type ' => 'text/html ' ]);
302+
303+ $ client ->respond (new RequestContext ([
304+ 'swooleResponse ' => $ swooleResponse ,
305+ ]), new OctaneResponse ($ response ));
306+ }
307+
308+ /** @doesNotPerformAssertions @test */
309+ public function test_respond_method_send_chunked_response_to_swoole (): void
310+ {
311+ $ client = new SwooleClient (6 );
312+
313+ $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
314+
315+ $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
316+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' );
317+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' );
318+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ));
319+ $ swooleResponse ->shouldReceive ('write ' )->once ()->with ('Hello ' );
320+ $ swooleResponse ->shouldReceive ('write ' )->once ()->with ('World ' );
321+ $ swooleResponse ->shouldReceive ('end ' )->once ();
322+
323+ $ response = new Response ('Hello World ' , 200 , ['Content-Type ' => 'text/html ' ]);
324+
325+ $ client ->respond (new RequestContext ([
326+ 'swooleResponse ' => $ swooleResponse ,
327+ ]), new OctaneResponse ($ response ));
328+ }
302329}
0 commit comments