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.
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
26 require_once dirname(dirname(__FILE__
)) . DIRECTORY_SEPARATOR
. 'TestHelper.php';
31 require_once 'Zend/Debug.php';
36 * @subpackage UnitTests
37 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38 * @license http://framework.zend.com/license/new-bsd New BSD License
41 class Zend_DebugTest
extends PHPUnit_Framework_TestCase
44 public function testDebugDefaultSapi()
46 $sapi = php_sapi_name();
47 Zend_Debug
::setSapi(null);
49 $result = Zend_Debug
::Dump($data, null, false);
50 $this->assertEquals($sapi, Zend_Debug
::getSapi());
53 public function testDebugDump()
55 Zend_Debug
::setSapi('cli');
57 $result = Zend_Debug
::Dump($data, null, false);
58 $result = str_replace(array(PHP_EOL
, "\n"), '_', $result);
59 $expected = "__string(6) \"string\"__";
60 $this->assertEquals($expected, $result);
63 public function testDebugCgi()
65 Zend_Debug
::setSapi('cgi');
67 $result = Zend_Debug
::Dump($data, null, false);
69 // Has to check for two strings, because xdebug internally handles CLI vs Web
70 $this->assertContains($result,
72 "<pre>string(6) \"string\"\n</pre>",
73 "<pre>string(6) "string"\n</pre>",
78 public function testDebugDumpEcho()
80 Zend_Debug
::setSapi('cli');
84 $result1 = Zend_Debug
::Dump($data, null, true);
85 $result2 = ob_get_contents();
88 $this->assertContains('string(6) "string"', $result1);
89 $this->assertEquals($result1, $result2);
92 public function testDebugDumpLabel()
94 Zend_Debug
::setSapi('cli');
97 $result = Zend_Debug
::Dump($data, $label, false);
98 $result = str_replace(array(PHP_EOL
, "\n"), '_', $result);
99 $expected = "_{$label} _string(6) \"string\"__";
100 $this->assertEquals($expected, $result);
107 public function testXdebugEnabledAndNonCliSapiDoesNotEscapeSpecialChars()
109 if(!extension_loaded('xdebug')) {
110 $this->markTestSkipped("This test only works in combination with xdebug.");
113 Zend_Debug
::setSapi('apache');
114 $a = array("a" => "b");
116 $result = Zend_Debug
::dump($a, "LABEL", false);
117 $this->assertContains("<pre>", $result);
118 $this->assertContains("</pre>", $result);