Leevel 响应转 Swoole 响应

Testing Is Documentation

tests/Protocol/Leevel2SwooleTest.phpLeevel 响应转 Swoole 响应 - 图1

Leevel 响应转 Swoole 响应后,然后传递给 Swoole 完成响应给用户。

Uses

  1. <?php
  2. use Leevel\Http\RedirectResponse;
  3. use Leevel\Http\Response;
  4. use Leevel\Protocol\Leevel2Swoole;
  5. use Swoole\Http\Response as SwooleHttpResponse;

转换 Leevel 响应的 header

  1. public function testResponseWithHeader(): void
  2. {
  3. $leevel2Swoole = new Leevel2Swoole();
  4. $swooleResponse = $this->createMock(SwooleHttpResponse::class);
  5. $response = new Response('hello');
  6. $response->withHeaders([
  7. 'foo' => 'bar',
  8. 'hello' => 'world',
  9. ]);
  10. $leevel2Swoole->createResponse($response, $swooleResponse);
  11. $this->assertInstanceOf(SwooleHttpResponse::class, $swooleResponse);
  12. }

转换 Leevel 响应的 cookie

  1. public function testResponseWithCookie(): void
  2. {
  3. $leevel2Swoole = new Leevel2Swoole();
  4. $swooleResponse = $this->createMock(SwooleHttpResponse::class);
  5. $response = new Response('hello');
  6. $response->withCookies([
  7. 'foo' => 'bar',
  8. 'hello' => 'world',
  9. ]);
  10. $leevel2Swoole->createResponse($response, $swooleResponse);
  11. $this->assertInstanceOf(SwooleHttpResponse::class, $swooleResponse);
  12. }

转换 Leevel 跳转响应

  1. public function testRedirectResponse(): void
  2. {
  3. $leevel2Swoole = new Leevel2Swoole();
  4. $swooleResponse = $this->createMock(SwooleHttpResponse::class);
  5. $response = new RedirectResponse('https://queryphp.com');
  6. $leevel2Swoole->createResponse($response, $swooleResponse);
  7. $this->assertInstanceOf(SwooleHttpResponse::class, $swooleResponse);
  8. }