zend-framework-1.x-on-git /tests/Zend/DebugTest.php

Language PHP Lines 116
MD5 Hash e98b765722a94ab5e072bba9fdc9ab55 Estimated Cost $1,507 (why?)
Repository https://bitbucket.org/dbaltas/zend-framework-1.x-on-git.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Debug
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id $
 */

/**
 * Zend_Debug
 */
require_once 'Zend/Debug.php';

/**
 * @category   Zend
 * @package    Zend_Debug
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @group      Zend_Debug
 */
class Zend_DebugTest extends PHPUnit_Framework_TestCase
{

    public function testDebugDefaultSapi()
    {
        $sapi = php_sapi_name();
        Zend_Debug::setSapi(null);
        $data = 'string';
        $result = Zend_Debug::Dump($data, null, false);
        $this->assertEquals($sapi, Zend_Debug::getSapi());
    }

    public function testDebugDump()
    {
        Zend_Debug::setSapi('cli');
        $data = 'string';
        $result = Zend_Debug::Dump($data, null, false);
        $result = str_replace(array(PHP_EOL, "\n"), '_', $result);
        $expected = "__string(6) \"string\"__";
        $this->assertEquals($expected, $result);
    }

    public function testDebugCgi()
    {
        Zend_Debug::setSapi('cgi');
        $data = 'string';
        $result = Zend_Debug::Dump($data, null, false);

        // Has to check for two strings, because xdebug internally handles CLI vs Web
        $this->assertContains($result,
            array(
                "<pre>string(6) \"string\"\n</pre>",
                "<pre>string(6) &quot;string&quot;\n</pre>",
            )
        );
    }

    public function testDebugDumpEcho()
    {
        Zend_Debug::setSapi('cli');
        $data = 'string';

        ob_start();
        $result1 = Zend_Debug::Dump($data, null, true);
        $result2 = ob_get_clean();

        $this->assertContains('string(6) "string"', $result1);
        $this->assertEquals($result1, $result2);
    }

    public function testDebugDumpLabel()
    {
        Zend_Debug::setSapi('cli');
        $data = 'string';
        $label = 'LABEL';
        $result = Zend_Debug::Dump($data, $label, false);
        $result = str_replace(array(PHP_EOL, "\n"), '_', $result);
        $expected = "_{$label} _string(6) \"string\"__";
        $this->assertEquals($expected, $result);
    }

    /**
     * @group ZF-4136
     * @group ZF-1663
     */
    public function testXdebugEnabledAndNonCliSapiDoesNotEscapeSpecialChars()
    {
        if(!extension_loaded('xdebug')) {
            $this->markTestSkipped("This test only works in combination with xdebug.");
        }

        Zend_Debug::setSapi('apache');
        $a = array("a" => "b");

        $result = Zend_Debug::dump($a, "LABEL", false);
        $this->assertContains("<pre>", $result);
        $this->assertContains("</pre>", $result);
    }

}
Back to Top