Skip to content

Commit 74a000b

Browse files
authored
Test streamed response (#157)
* Test streamed response * Update mock
1 parent 5859fc5 commit 74a000b

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/RoadRunnerClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Mockery;
1313
use Psr\Http\Message\ResponseInterface;
1414
use Spiral\RoadRunner\Http\PSR7Worker;
15+
use Symfony\Component\HttpFoundation\StreamedResponse;
1516

1617
class RoadRunnerClientTest extends TestCase
1718
{
@@ -46,6 +47,23 @@ public function test_respond_method_send_response_to_roadrunner()
4647
]), new OctaneResponse(new Response('Hello World', 200)));
4748
}
4849

50+
/** @doesNotPerformAssertions @test */
51+
public function test_respond_method_send_streamed_response_to_roadrunner()
52+
{
53+
$client = new RoadRunnerClient($psr7Client = Mockery::mock(PSR7Worker::class));
54+
55+
$psr7Request = (new ServerRequestFactory)->createServerRequest('GET', '/home');
56+
$psr7Request = $psr7Request->withQueryParams(['name' => 'Taylor']);
57+
58+
$psr7Client->shouldReceive('respond')->once()->with(Mockery::type(ResponseInterface::class));
59+
60+
$client->respond(new RequestContext([
61+
'psr7Request' => $psr7Request,
62+
]), new OctaneResponse(new StreamedResponse(function () {
63+
echo 'Hello World';
64+
}, 200)));
65+
}
66+
4967
/** @doesNotPerformAssertions @test */
5068
public function test_error_method_sends_error_response_to_roadrunner()
5169
{

tests/SwooleClientTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Laravel\Octane\RequestContext;
1010
use Laravel\Octane\Swoole\SwooleClient;
1111
use Mockery;
12+
use Symfony\Component\HttpFoundation\StreamedResponse;
1213

1314
class SwooleClientTest extends TestCase
1415
{
@@ -133,6 +134,27 @@ public function test_respond_method_send_response_to_swoole()
133134
]), new OctaneResponse(new Response('Hello World', 200, ['Content-Type' => 'text/html'])));
134135
}
135136

137+
/** @doesNotPerformAssertions @test */
138+
public function test_respond_method_send_streamed_response_to_swoole()
139+
{
140+
$client = new SwooleClient;
141+
142+
$swooleResponse = Mockery::mock('Swoole\Http\Response');
143+
144+
$swooleResponse->shouldReceive('status')->once()->with(200);
145+
$swooleResponse->shouldReceive('header')->once()->with('Cache-Control', 'no-cache, private');
146+
$swooleResponse->shouldReceive('header')->once()->with('Content-Type', 'text/html');
147+
$swooleResponse->shouldReceive('header')->once()->with('Date', Mockery::type('string'));
148+
$swooleResponse->shouldReceive('write')->once()->with('Hello World');
149+
$swooleResponse->shouldReceive('end')->once();
150+
151+
$client->respond(new RequestContext([
152+
'swooleResponse' => $swooleResponse,
153+
]), new OctaneResponse(new StreamedResponse(function () {
154+
echo 'Hello World';
155+
}, 200, ['Content-Type' => 'text/html'])));
156+
}
157+
136158
/** @doesNotPerformAssertions @test */
137159
public function test_error_method_sends_error_response_to_swoole()
138160
{

0 commit comments

Comments
 (0)