InternalTest.php 2.3 KB

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