mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 19:58:22 +08:00
Merge branch 'master' of https://github.com/dickens7/hyperf into pr/455
This commit is contained in:
commit
333c99c18b
54
src/http-message/tests/SwooleStreamTest.php
Normal file
54
src/http-message/tests/SwooleStreamTest.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://doc.hyperf.io
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace HyperfTest\HttpMessage;
|
||||
|
||||
use Hyperf\HttpMessage\Server\Response;
|
||||
use Hyperf\HttpMessage\Stream\SwooleFileStream;
|
||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Swoole\Http\Response as SwooleResponse;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class SwooleStreamTest extends TestCase
|
||||
{
|
||||
public function testSwooleFileStream()
|
||||
{
|
||||
$swooleResponse = Mockery::mock(SwooleResponse::class);
|
||||
$file = __FILE__;
|
||||
$swooleResponse->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());
|
||||
}
|
||||
}
|
@ -48,5 +48,5 @@ interface ResponseInterface
|
||||
/**
|
||||
* Create a new file download response.
|
||||
*/
|
||||
public function download(string $pathToFile, string $name = ''): PsrResponseInterface;
|
||||
public function download(string $file, string $name = ''): PsrResponseInterface;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user