diff --git a/src/http-message/tests/SwooleStreamTest.php b/src/http-message/tests/SwooleStreamTest.php new file mode 100644 index 000000000..83b6fdf2f --- /dev/null +++ b/src/http-message/tests/SwooleStreamTest.php @@ -0,0 +1,54 @@ +shouldReceive('sendfile')->with($file)->once()->andReturn(null); + $swooleResponse->shouldReceive('status')->with(Mockery::any())->once()->andReturn(200); + + $response = new Response($swooleResponse); + $response = $response->withBody(new SwooleFileStream($file)); + + $this->assertSame(null, $response->send()); + } + + public function testSwooleStream() + { + $swooleResponse = Mockery::mock(SwooleResponse::class); + $content = '{"id":1}'; + $swooleResponse->shouldReceive('end')->with($content)->once()->andReturn(null); + $swooleResponse->shouldReceive('status')->with(Mockery::any())->once()->andReturn(200); + $swooleResponse->shouldReceive('header')->with('TOKEN', 'xxx')->once()->andReturn(null); + + $response = new Response($swooleResponse); + $response = $response->withBody(new SwooleStream($content))->withHeader('TOKEN', 'xxx'); + + $this->assertSame(null, $response->send()); + } +} diff --git a/src/http-server/src/Contract/ResponseInterface.php b/src/http-server/src/Contract/ResponseInterface.php index a73f3b6d2..ad11c9349 100644 --- a/src/http-server/src/Contract/ResponseInterface.php +++ b/src/http-server/src/Contract/ResponseInterface.php @@ -47,9 +47,9 @@ interface ResponseInterface /** * Create a new file download response. - * @param string $pathToFile + * @param string $file * @param string $name * @return PsrResponseInterface */ - public function download(string $pathToFile, string $name = ''): PsrResponseInterface; + public function download(string $file, string $name = ''): PsrResponseInterface; }