PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/DebugTest.php

https://bitbucket.org/dbaltas/zend-framework-1.x-on-git
PHP | 115 lines | 65 code | 14 blank | 36 comment | 1 complexity | e98b765722a94ab5e072bba9fdc9ab55 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. /**
  23. * Zend_Debug
  24. */
  25. require_once 'Zend/Debug.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Debug
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Debug
  33. */
  34. class Zend_DebugTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function testDebugDefaultSapi()
  37. {
  38. $sapi = php_sapi_name();
  39. Zend_Debug::setSapi(null);
  40. $data = 'string';
  41. $result = Zend_Debug::Dump($data, null, false);
  42. $this->assertEquals($sapi, Zend_Debug::getSapi());
  43. }
  44. public function testDebugDump()
  45. {
  46. Zend_Debug::setSapi('cli');
  47. $data = 'string';
  48. $result = Zend_Debug::Dump($data, null, false);
  49. $result = str_replace(array(PHP_EOL, "\n"), '_', $result);
  50. $expected = "__string(6) \"string\"__";
  51. $this->assertEquals($expected, $result);
  52. }
  53. public function testDebugCgi()
  54. {
  55. Zend_Debug::setSapi('cgi');
  56. $data = 'string';
  57. $result = Zend_Debug::Dump($data, null, false);
  58. // Has to check for two strings, because xdebug internally handles CLI vs Web
  59. $this->assertContains($result,
  60. array(
  61. "<pre>string(6) \"string\"\n</pre>",
  62. "<pre>string(6) &quot;string&quot;\n</pre>",
  63. )
  64. );
  65. }
  66. public function testDebugDumpEcho()
  67. {
  68. Zend_Debug::setSapi('cli');
  69. $data = 'string';
  70. ob_start();
  71. $result1 = Zend_Debug::Dump($data, null, true);
  72. $result2 = ob_get_clean();
  73. $this->assertContains('string(6) "string"', $result1);
  74. $this->assertEquals($result1, $result2);
  75. }
  76. public function testDebugDumpLabel()
  77. {
  78. Zend_Debug::setSapi('cli');
  79. $data = 'string';
  80. $label = 'LABEL';
  81. $result = Zend_Debug::Dump($data, $label, false);
  82. $result = str_replace(array(PHP_EOL, "\n"), '_', $result);
  83. $expected = "_{$label} _string(6) \"string\"__";
  84. $this->assertEquals($expected, $result);
  85. }
  86. /**
  87. * @group ZF-4136
  88. * @group ZF-1663
  89. */
  90. public function testXdebugEnabledAndNonCliSapiDoesNotEscapeSpecialChars()
  91. {
  92. if(!extension_loaded('xdebug')) {
  93. $this->markTestSkipped("This test only works in combination with xdebug.");
  94. }
  95. Zend_Debug::setSapi('apache');
  96. $a = array("a" => "b");
  97. $result = Zend_Debug::dump($a, "LABEL", false);
  98. $this->assertContains("<pre>", $result);
  99. $this->assertContains("</pre>", $result);
  100. }
  101. }