DebugTest.php 3.5 KB

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