|
3 | 3 | namespace Laravel\Octane\Tests; |
4 | 4 |
|
5 | 5 | use Exception; |
| 6 | +use Generator; |
| 7 | +use Hamcrest\Core\IsInstanceOf; |
6 | 8 | use Illuminate\Http\Request; |
7 | 9 | use Illuminate\Http\Response; |
8 | 10 | use Laminas\Diactoros\ServerRequestFactory; |
|
11 | 13 | use Laravel\Octane\RoadRunner\RoadRunnerClient; |
12 | 14 | use Mockery; |
13 | 15 | use Psr\Http\Message\ResponseInterface; |
| 16 | +use Spiral\RoadRunner\Http\HttpWorker; |
14 | 17 | use Spiral\RoadRunner\Http\PSR7Worker; |
15 | 18 | use Symfony\Component\HttpFoundation\StreamedResponse; |
16 | 19 |
|
@@ -63,6 +66,32 @@ public function test_respond_method_send_streamed_response_to_roadrunner() |
63 | 66 | }, 200))); |
64 | 67 | } |
65 | 68 |
|
| 69 | + /** @doesNotPerformAssertions @test */ |
| 70 | + public function test_respond_method_send_streamed_generator_response_to_roadrunner() |
| 71 | + { |
| 72 | + $client = new RoadRunnerClient($psr7Client = Mockery::mock(PSR7Worker::class)); |
| 73 | + |
| 74 | + $psr7Request = (new ServerRequestFactory)->createServerRequest('GET', '/home'); |
| 75 | + $psr7Request = $psr7Request->withQueryParams(['name' => 'Taylor']); |
| 76 | + |
| 77 | + $httpWorker = Mockery::mock(HttpWorker::class); |
| 78 | + |
| 79 | + $responseCallback = function (): Generator { |
| 80 | + yield 'Hello World'; |
| 81 | + }; |
| 82 | + |
| 83 | + $psr7Client->shouldReceive('getHttpWorker')->once()->andReturn($httpWorker); |
| 84 | + $httpWorker->shouldReceive('respond')->once()->with( |
| 85 | + 200, |
| 86 | + IsInstanceOf::anInstanceOf(Generator::class), |
| 87 | + Mockery::hasKey('cache-control'), |
| 88 | + ); |
| 89 | + |
| 90 | + $client->respond(new RequestContext([ |
| 91 | + 'psr7Request' => $psr7Request, |
| 92 | + ]), new OctaneResponse(new StreamedResponse($responseCallback, 200))); |
| 93 | + } |
| 94 | + |
66 | 95 | /** @doesNotPerformAssertions @test */ |
67 | 96 | public function test_error_method_sends_error_response_to_roadrunner() |
68 | 97 | { |
|
0 commit comments