ControllerBase.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace EasySwoole\HttpAnnotation\Tests;
  3. use EasySwoole\Http\Request;
  4. use EasySwoole\Http\Response;
  5. trait ControllerBase
  6. {
  7. protected function fakeRequest(string $requestPath = '/',array $query = null,array $post = []):Request
  8. {
  9. if($query === null){
  10. $query = [
  11. "groupParamA"=>"groupParamA",
  12. 'groupParamB'=>"groupParamB"
  13. ];
  14. }else if(!empty($query)){
  15. $query = $query + [
  16. "groupParamA"=>"groupParamA",
  17. 'groupParamB'=>"groupParamB"
  18. ];
  19. }
  20. $request = new Request();
  21. $request->getUri()->withPath($requestPath);
  22. //全局的参数
  23. $request->withQueryParams($query);
  24. if(!empty($post)){
  25. $request->withMethod('POST')->withParsedBody($post);
  26. }else{
  27. $request->withMethod('GET');
  28. }
  29. return $request;
  30. }
  31. protected function fakeResponse():Response
  32. {
  33. return new Response();
  34. }
  35. }