ExceptionTest.php 2.6 KB

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