ExceptionTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Tests KO7 Exception Class
  4. *
  5. * @group ko7
  6. * @group ko7.core
  7. * @group ko7.core.exception
  8. *
  9. * @package KO7
  10. * @category Tests
  11. *
  12. * @copyright (c) 2007-2016 Kohana Team
  13. * @copyright (c) since 2016 Koseven Team
  14. * @license https://koseven.dev/LICENSE
  15. */
  16. class KO7_ExceptionTest extends Unittest_TestCase
  17. {
  18. /**
  19. * Provides test data for test_constructor()
  20. *
  21. * @return array
  22. */
  23. public function provider_constructor()
  24. {
  25. return [
  26. [[''], '', 0],
  27. [[':a'], ':a', 0],
  28. [[':a', NULL], ':a', 0],
  29. [[':a', []], ':a', 0],
  30. [[':a', [':a' => 'b']], 'b', 0],
  31. [[':a :b', [':a' => 'c', ':b' => 'd']], 'c d', 0],
  32. [[':a', NULL, 5], ':a', 5],
  33. // #3358
  34. [[':a', NULL, '3F000'], ':a', '3F000'],
  35. // #3404
  36. [[':a', NULL, '42S22'], ':a', '42S22'],
  37. // #3927
  38. [[':a', NULL, 'b'], ':a', 'b'],
  39. // #4039
  40. [[':a', NULL, '25P01'], ':a', '25P01'],
  41. ];
  42. }
  43. /**
  44. * Tests KO7_KO7_Exception::__construct()
  45. *
  46. * @test
  47. * @dataProvider provider_constructor
  48. * @covers KO7_KO7_Exception::__construct
  49. * @param array $arguments Arguments
  50. * @param string $expected_message Value from getMessage()
  51. * @param integer|string $expected_code Value from getCode()
  52. */
  53. public function test_constructor($arguments, $expected_message, $expected_code)
  54. {
  55. switch (count($arguments))
  56. {
  57. case 1:
  58. $exception = new KO7_Exception(reset($arguments));
  59. break;
  60. case 2:
  61. $exception = new KO7_Exception(reset($arguments), next($arguments));
  62. break;
  63. default:
  64. $exception = new KO7_Exception(reset($arguments), next($arguments), next($arguments));
  65. }
  66. $this->assertSame($expected_code, $exception->getCode());
  67. $this->assertSame($expected_message, $exception->getMessage());
  68. }
  69. /**
  70. * Provides test data for test_text()
  71. *
  72. * @return array
  73. */
  74. public function provider_text()
  75. {
  76. return [
  77. [new KO7_Exception('foobar'), $this->dirSeparator('KO7_Exception [ 0 ]: foobar ~ SYSPATH/tests/ko7/ExceptionTest.php [ '.__LINE__.' ]')],
  78. ];
  79. }
  80. /**
  81. * Tests KO7_Exception::text()
  82. *
  83. * @test
  84. * @dataProvider provider_text
  85. * @covers KO7_Exception::text
  86. * @param object $exception exception to test
  87. * @param string $expected expected output
  88. */
  89. public function test_text($exception, $expected)
  90. {
  91. $this->assertEquals($expected, KO7_Exception::text($exception));
  92. }
  93. }