DispatchTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace think\tests;
  3. use GuzzleHttp\Psr7\Response;
  4. use Mockery;
  5. use PHPUnit\Framework\TestCase;
  6. use think\App;
  7. use think\Config;
  8. use think\Container;
  9. use think\Request;
  10. use think\route\Dispatch;
  11. use think\route\Rule;
  12. class DispatchTest extends TestCase
  13. {
  14. use InteractsWithApp;
  15. protected function setUp(): void
  16. {
  17. $this->prepareApp();
  18. // Mock config for Cookie dependency
  19. $this->config->shouldReceive('get')->with('cookie')->andReturn([
  20. 'expire' => 0,
  21. 'path' => '/',
  22. 'domain' => '',
  23. 'secure' => false,
  24. 'httponly' => false,
  25. 'samesite' => ''
  26. ]);
  27. }
  28. protected function tearDown(): void
  29. {
  30. Mockery::close();
  31. }
  32. public function testPsr7Response()
  33. {
  34. $request = Mockery::mock(Request::class);
  35. $rule = Mockery::mock(Rule::class);
  36. $dispatch = new class($request, $rule, '') extends Dispatch {
  37. public function exec()
  38. {
  39. return new Response(200, ['framework' => ['tp', 'thinkphp'], 'psr' => 'psr-7'], '123');
  40. }
  41. };
  42. // Mock request methods that might be called
  43. $request->shouldReceive('isJson')->andReturn(false);
  44. $response = $dispatch->run();
  45. $this->assertInstanceOf(\think\Response::class, $response);
  46. $this->assertEquals('123', $response->getContent());
  47. $this->assertEquals('tp, thinkphp', $response->getHeader('framework'));
  48. $this->assertEquals('psr-7', $response->getHeader('psr'));
  49. }
  50. }