DebugTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Tests Kohana Core
  4. *
  5. * @TODO Use a virtual filesystem (see phpunit doc on mocking fs) for find_file etc.
  6. *
  7. * @group kohana
  8. * @group kohana.core
  9. * @group kohana.core.debug
  10. *
  11. * @package Kohana
  12. * @category Tests
  13. * @author Kohana Team
  14. * @author Jeremy Bush <contractfrombelow@gmail.com>
  15. * @copyright (c) Kohana Team
  16. * @license https://koseven.ga/LICENSE.md
  17. */
  18. class Kohana_DebugTest extends Unittest_TestCase
  19. {
  20. /**
  21. * Provides test data for test_debug()
  22. *
  23. * @return array
  24. */
  25. public function provider_vars()
  26. {
  27. return [
  28. // $thing, $expected
  29. [['foobar'], "<pre class=\"debug\"><small>array</small><span>(1)</span> <span>(\n 0 => <small>string</small><span>(6)</span> \"foobar\"\n)</span></pre>"],
  30. ];
  31. }
  32. /**
  33. * Tests Debug::vars()
  34. *
  35. * @test
  36. * @dataProvider provider_vars
  37. * @covers Debug::vars
  38. * @param boolean $thing The thing to debug
  39. * @param boolean $expected Output for Debug::vars
  40. */
  41. public function test_var($thing, $expected)
  42. {
  43. $this->assertEquals($expected, Debug::vars($thing));
  44. }
  45. /**
  46. * Provides test data for testDebugPath()
  47. *
  48. * @return array
  49. */
  50. public function provider_debug_path()
  51. {
  52. return [
  53. [
  54. SYSPATH.'classes'.DIRECTORY_SEPARATOR.'kohana'.EXT,
  55. 'SYSPATH'.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.'kohana.php'
  56. ],
  57. [
  58. MODPATH.$this->dirSeparator('unittest/classes/kohana/unittest/runner').EXT,
  59. $this->dirSeparator('MODPATH/unittest/classes/kohana/unittest/runner').EXT
  60. ],
  61. ];
  62. }
  63. /**
  64. * Tests Debug::path()
  65. *
  66. * @test
  67. * @dataProvider provider_debug_path
  68. * @covers Debug::path
  69. * @param boolean $path Input for Debug::path
  70. * @param boolean $expected Output for Debug::path
  71. */
  72. public function test_debug_path($path, $expected)
  73. {
  74. $this->assertEquals($expected, Debug::path($path));
  75. }
  76. /**
  77. * Provides test data for test_dump()
  78. *
  79. * @return array
  80. */
  81. public function provider_dump()
  82. {
  83. return [
  84. ['foobar', 128, 10, '<small>string</small><span>(6)</span> "foobar"'],
  85. ['foobar', 2, 10, '<small>string</small><span>(6)</span> "fo&nbsp;&hellip;"'],
  86. [NULL, 128, 10, '<small>NULL</small>'],
  87. [TRUE, 128, 10, '<small>bool</small> TRUE'],
  88. [['foobar'], 128, 10, "<small>array</small><span>(1)</span> <span>(\n 0 => <small>string</small><span>(6)</span> \"foobar\"\n)</span>"],
  89. [new StdClass, 128, 10, "<small>object</small> <span>stdClass(0)</span> <code>{\n}</code>"],
  90. ["fo\x6F\xFF\x00bar\x8F\xC2\xB110", 128, 10, '<small>string</small><span>(10)</span> "foobar±10"'],
  91. [['level1' => ['level2' => ['level3' => ['level4' => ['value' => 'something']]]]], 128, 4,
  92. '<small>array</small><span>(1)</span> <span>(
  93. "level1" => <small>array</small><span>(1)</span> <span>(
  94. "level2" => <small>array</small><span>(1)</span> <span>(
  95. "level3" => <small>array</small><span>(1)</span> <span>(
  96. "level4" => <small>array</small><span>(1)</span> (
  97. ...
  98. )
  99. )</span>
  100. )</span>
  101. )</span>
  102. )</span>'],
  103. ];
  104. }
  105. /**
  106. * Tests Debug::dump()
  107. *
  108. * @test
  109. * @dataProvider provider_dump
  110. * @covers Debug::dump
  111. * @covers Debug::_dump
  112. * @param object $exception exception to test
  113. * @param string $expected expected output
  114. */
  115. public function test_dump($input, $length, $limit, $expected)
  116. {
  117. $this->assertEquals($expected, Debug::dump($input, $length, $limit));
  118. }
  119. }