Leevel 响应转 Swoole 响应
Testing Is Documentation
tests/Protocol/Leevel2SwooleTest.php
Leevel 响应转 Swoole 响应后,然后传递给 Swoole 完成响应给用户。
Uses
<?php
use Leevel\Http\RedirectResponse;
use Leevel\Http\Response;
use Leevel\Protocol\Leevel2Swoole;
use Swoole\Http\Response as SwooleHttpResponse;
转换 Leevel 响应的 header
public function testResponseWithHeader(): void
{
$leevel2Swoole = new Leevel2Swoole();
$swooleResponse = $this->createMock(SwooleHttpResponse::class);
$response = new Response('hello');
$response->withHeaders([
'foo' => 'bar',
'hello' => 'world',
]);
$leevel2Swoole->createResponse($response, $swooleResponse);
$this->assertInstanceOf(SwooleHttpResponse::class, $swooleResponse);
}
转换 Leevel 响应的 cookie
public function testResponseWithCookie(): void
{
$leevel2Swoole = new Leevel2Swoole();
$swooleResponse = $this->createMock(SwooleHttpResponse::class);
$response = new Response('hello');
$response->withCookies([
'foo' => 'bar',
'hello' => 'world',
]);
$leevel2Swoole->createResponse($response, $swooleResponse);
$this->assertInstanceOf(SwooleHttpResponse::class, $swooleResponse);
}
转换 Leevel 跳转响应
public function testRedirectResponse(): void
{
$leevel2Swoole = new Leevel2Swoole();
$swooleResponse = $this->createMock(SwooleHttpResponse::class);
$response = new RedirectResponse('https://queryphp.com');
$leevel2Swoole->createResponse($response, $swooleResponse);
$this->assertInstanceOf(SwooleHttpResponse::class, $swooleResponse);
}