|
9 | 9 | use Laravel\Octane\RequestContext; |
10 | 10 | use Laravel\Octane\Swoole\SwooleClient; |
11 | 11 | use Mockery; |
| 12 | +use Swoole\Http\Response as SwooleResponse; |
12 | 13 | use Symfony\Component\HttpFoundation\StreamedResponse; |
13 | 14 |
|
14 | 15 | class SwooleClientTest extends TestCase |
@@ -280,4 +281,47 @@ public function test_error_method_sends_detailed_error_response_to_swoole_in_deb |
280 | 281 | $swooleResponse->shouldHaveReceived('header')->with('Content-Type', 'text/plain'); |
281 | 282 | $swooleResponse->shouldHaveReceived('end')->with((string) $e); |
282 | 283 | } |
| 284 | + |
| 285 | + /** @doesNotPerformAssertions @test */ |
| 286 | + public function test_respond_method_send_not_chunked_response_to_swoole(): void |
| 287 | + { |
| 288 | + $client = new SwooleClient; |
| 289 | + |
| 290 | + $swooleResponse = Mockery::mock(SwooleResponse::class); |
| 291 | + |
| 292 | + $swooleResponse->shouldReceive('status')->once()->with(200); |
| 293 | + $swooleResponse->shouldReceive('header')->once()->with('Cache-Control', 'no-cache, private'); |
| 294 | + $swooleResponse->shouldReceive('header')->once()->with('Content-Type', 'text/html'); |
| 295 | + $swooleResponse->shouldReceive('header')->once()->with('Date', Mockery::type('string')); |
| 296 | + $swooleResponse->shouldReceive('write')->never(); |
| 297 | + $swooleResponse->shouldReceive('end')->once()->with('Hello World'); |
| 298 | + |
| 299 | + $response = new Response('Hello World', 200, ['Content-Type' => 'text/html']); |
| 300 | + |
| 301 | + $client->respond(new RequestContext([ |
| 302 | + 'swooleResponse' => $swooleResponse, |
| 303 | + ]), new OctaneResponse($response)); |
| 304 | + } |
| 305 | + |
| 306 | + /** @doesNotPerformAssertions @test */ |
| 307 | + public function test_respond_method_send_chunked_response_to_swoole(): void |
| 308 | + { |
| 309 | + $client = new SwooleClient(6); |
| 310 | + |
| 311 | + $swooleResponse = Mockery::mock('Swoole\Http\Response'); |
| 312 | + |
| 313 | + $swooleResponse->shouldReceive('status')->once()->with(200); |
| 314 | + $swooleResponse->shouldReceive('header')->once()->with('Cache-Control', 'no-cache, private'); |
| 315 | + $swooleResponse->shouldReceive('header')->once()->with('Content-Type', 'text/html'); |
| 316 | + $swooleResponse->shouldReceive('header')->once()->with('Date', Mockery::type('string')); |
| 317 | + $swooleResponse->shouldReceive('write')->once()->with('Hello '); |
| 318 | + $swooleResponse->shouldReceive('write')->once()->with('World'); |
| 319 | + $swooleResponse->shouldReceive('end')->once(); |
| 320 | + |
| 321 | + $response = new Response('Hello World', 200, ['Content-Type' => 'text/html']); |
| 322 | + |
| 323 | + $client->respond(new RequestContext([ |
| 324 | + 'swooleResponse' => $swooleResponse, |
| 325 | + ]), new OctaneResponse($response)); |
| 326 | + } |
283 | 327 | } |
0 commit comments