DebugTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Debug
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Test helper
  23. */
  24. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  25. /**
  26. * Zend_Debug
  27. */
  28. require_once 'Zend/Debug.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Debug
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_DebugTest extends PHPUnit_Framework_TestCase
  37. {
  38. public function testDebugDefaultSapi()
  39. {
  40. $sapi = php_sapi_name();
  41. Zend_Debug::setSapi(null);
  42. $data = 'string';
  43. $result = Zend_Debug::Dump($data, null, false);
  44. $this->assertEquals($sapi, Zend_Debug::getSapi());
  45. }
  46. public function testDebugDump()
  47. {
  48. Zend_Debug::setSapi('cli');
  49. $data = 'string';
  50. $result = Zend_Debug::Dump($data, null, false);
  51. $result = str_replace(array(PHP_EOL, "\n"), '_', $result);
  52. $expected = "__string(6) \"string\"__";
  53. $this->assertEquals($expected, $result);
  54. }
  55. public function testDebugCgi()
  56. {
  57. Zend_Debug::setSapi('cgi');
  58. $data = 'string';
  59. $result = Zend_Debug::Dump($data, null, false);
  60. // Has to check for two strings, because xdebug internally handles CLI vs Web
  61. $this->assertContains($result,
  62. array(
  63. "<pre>string(6) \"string\"\n</pre>",
  64. "<pre>string(6) &quot;string&quot;\n</pre>",
  65. )
  66. );
  67. }
  68. public function testDebugDumpEcho()
  69. {
  70. Zend_Debug::setSapi('cli');
  71. $data = 'string';
  72. ob_start();
  73. $result1 = Zend_Debug::Dump($data, null, true);
  74. $result2 = ob_get_contents();
  75. ob_end_clean();
  76. $this->assertContains('string(6) "string"', $result1);
  77. $this->assertEquals($result1, $result2);
  78. }
  79. public function testDebugDumpLabel()
  80. {
  81. Zend_Debug::setSapi('cli');
  82. $data = 'string';
  83. $label = 'LABEL';
  84. $result = Zend_Debug::Dump($data, $label, false);
  85. $result = str_replace(array(PHP_EOL, "\n"), '_', $result);
  86. $expected = "_{$label} _string(6) \"string\"__";
  87. $this->assertEquals($expected, $result);
  88. }
  89. /**
  90. * @group ZF-4136
  91. * @group ZF-1663
  92. */
  93. public function testXdebugEnabledAndNonCliSapiDoesNotEscapeSpecialChars()
  94. {
  95. if(!extension_loaded('xdebug')) {
  96. $this->markTestSkipped("This test only works in combination with xdebug.");
  97. }
  98. Zend_Debug::setSapi('apache');
  99. $a = array("a" => "b");
  100. $result = Zend_Debug::dump($a, "LABEL", false);
  101. $this->assertContains("<pre>", $result);
  102. $this->assertContains("</pre>", $result);
  103. }
  104. }