InternalTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Unit tests for internal request client
  4. *
  5. * @group ko7
  6. * @group ko7.core
  7. * @group ko7.core.request
  8. * @group ko7.core.request.client
  9. * @group ko7.core.request.client.internal
  10. *
  11. * @package KO7
  12. * @category Tests
  13. *
  14. * @copyright (c) 2007-2016 Kohana Team
  15. * @copyright (c) since 2016 Koseven Team
  16. * @license https://koseven.dev/LICENSE
  17. */
  18. class KO7_Request_Client_InternalTest extends Unittest_TestCase
  19. {
  20. protected $_log_object;
  21. // @codingStandardsIgnoreStart
  22. public function setUp(): void
  23. // @codingStandardsIgnoreEnd
  24. {
  25. parent::setUp();
  26. // temporarily save $log object
  27. $this->_log_object = KO7::$log;
  28. KO7::$log = NULL;
  29. }
  30. // @codingStandardsIgnoreStart
  31. public function tearDown(): void
  32. // @codingStandardsIgnoreEnd
  33. {
  34. // re-assign log object
  35. KO7::$log = $this->_log_object;
  36. parent::tearDown();
  37. }
  38. public function provider_response_failure_status()
  39. {
  40. return [
  41. ['', 'Welcome', 'missing_action', 'Welcome/missing_action', 404],
  42. ['KO7', 'missing_controller', 'index', 'KO7/missing_controller/index', 404],
  43. ['', 'Template', 'missing_action', 'KO7/Template/missing_action', 500],
  44. ];
  45. }
  46. /**
  47. * Tests for correct exception messages
  48. *
  49. * @test
  50. * @dataProvider provider_response_failure_status
  51. *
  52. * @return null
  53. */
  54. public function test_response_failure_status($directory, $controller, $action, $uri, $expected)
  55. {
  56. // Mock for request object
  57. $request = $this->createMock('Request', ['directory', 'controller', 'action', 'uri', 'response', 'method'], [$uri]);
  58. $request->expects($this->any())
  59. ->method('directory')
  60. ->will($this->returnValue($directory));
  61. $request->expects($this->any())
  62. ->method('controller')
  63. ->will($this->returnValue($controller));
  64. $request->expects($this->any())
  65. ->method('action')
  66. ->will($this->returnValue($action));
  67. $request->expects($this->any())
  68. ->method('uri')
  69. ->will($this->returnValue($uri));
  70. $request->expects($this->any())
  71. ->method('execute')
  72. ->will($this->returnValue($this->createMock('Response')));
  73. // mock `method` method to avoid fatals in newer versions of PHPUnit
  74. $request->expects($this->any())
  75. ->method('method')
  76. ->withAnyParameters();
  77. $internal_client = new Request_Client_Internal;
  78. $response = $internal_client->execute($request);
  79. $this->assertSame($expected, $response->status());
  80. }
  81. }