Source for file test.php
Documentation is available at test.php
require_once 'PHPUnit.php';
require_once 'Var_Dump.php';
class Var_DumpTest extends PHPUnit_TestCase {
function Var_DumpTest ($name) {
$this->PHPUnit_TestCase ($name);
$this->vd = new Var_Dump (array ('display_mode'=> 'Text'));
function test_type_int () {
$this->assertEquals ('int -2147483647',$this->vd->toString (-2147483647 ));
$this->assertEquals ('int 0',$this->vd->toString (0 ));
$this->assertEquals ('int 2147483647',$this->vd->toString (2147483647 ));
function test_type_bool () {
$this->assertEquals ('bool false',$this->vd->toString (FALSE ));
$this->assertEquals ('bool true',$this->vd->toString (TRUE ));
function test_type_float () {
$this->assertEquals ('float 12.345678',$this->vd->toString (12.345678 ));
$this->assertEquals ('float -12.345678',$this->vd->toString (-12.345678 ));
$this->assertEquals ('float 2147483648',$this->vd->toString (2147483648 ));
$this->assertEquals ('float -2147483648',$this->vd->toString (-2147483648 ));
function test_type_resource () {
$this->assertRegExp ('/^resource\(stream\)\s[0-9]+$/',$this->vd->toString ($dh));
$this->assertTrue (FALSE ,'Unable to open directory /tmp, ');
$this->assertTrue (FALSE ,'Unable to open directory /tmp, ');
function test_type_null () {
$this->assertEquals ('NULL',$this->vd->toString (NULL ));
function test_type_array () {
' key1 => string(44) The quick brown'. "\n".
' key2 => &array(3) {'. "\n".
' 2 => float 123.45'. "\n".
$this->vd->toString ($GLOBALS['array'])
function test_type_object () {
'object(object)(3) {'. "\n".
' key1 => string(44) The quick brown'. "\n".
' key2 => array(3) {'. "\n".
' 2 => float 123.45'. "\n".
$this->vd->toString (new object ()));
/*======================*/
/* Test "Text" Renderer */
/*======================*/
function test_renderer_text () {
array ('display_mode'=> 'Text'),
'before_num_key' => '\'',
' "key1" -> [string(44)] The quick brown *'. "\n".
' fox jumped over *'. "\n".
' "key2" -> &array(3) ('. "\n".
' \'0\' -> [bool] true'. "\n".
' \'1\' -> [int] 123'. "\n".
' \'2\' -> [float] 123.45'. "\n".
' "key3" -> [NULL]'. "\n".
Var_Dump ::display ($GLOBALS['array'],TRUE )
/*============================*/
/* Test "HTML4_Text" Renderer */
/*============================*/
function test_renderer_html4_text () {
Var_Dump ::displayInit (array ('display_mode'=> 'HTML4_Text'));
' key1 => <font color="#006600">string(44)</font> <font color="#339900">The quick brown'. "\n".
'</font> <font color="#339900">fox jumped over'. "\n".
'</font> <font color="#339900">the lazy dog</font>'. "\n".
' key2 => &array(3) {'. "\n".
' 0 => <font color="#006600">bool</font> <font color="#339900">true</font>'. "\n".
' 1 => <font color="#006600">int</font> <font color="#339900">123</font>'. "\n".
' 2 => <font color="#006600">float</font> <font color="#339900">123.45</font>'. "\n".
' key3 => <font color="#006600">NULL</font>'. "\n".
Var_Dump ::display ($GLOBALS['array'],TRUE )
/*============================*/
/* Test "XHTML_Text" Renderer */
/*============================*/
function test_renderer_xhtml_text () {
Var_Dump ::displayInit (array ('display_mode'=> 'XHTML_Text'));
'<pre class="var_dump">array(3) {'. "\n".
' key1 => <span class="type">string(44)</span> <span class="value">The quick brown'. "\n".
'</span> <span class="value">fox jumped over'. "\n".
'</span> <span class="value">the lazy dog</span>'. "\n".
' key2 => &array(3) {'. "\n".
' 0 => <span class="type">bool</span> <span class="value">true</span>'. "\n".
' 1 => <span class="type">int</span> <span class="value">123</span>'. "\n".
' 2 => <span class="type">float</span> <span class="value">123.45</span>'. "\n".
' key3 => <span class="type">NULL</span>'. "\n".
Var_Dump ::display ($GLOBALS['array'],TRUE )
/*=======================*/
/* Test "Table" Renderer */
/*=======================*/
function test_renderer_table () {
array ('display_mode'=> 'Table'),
'<caption>array(3)</caption>'.
'<td>The quick brown<br />'. "\n". 'fox jumped over<br />'. "\n". 'the lazy dog</td>'.
'<caption>&array(3)</caption>'.
'<tr><td>0</td><td>[bool]</td><td>true</td></tr>'.
'<tr><td>1</td><td>[int]</td><td>123</td></tr>'.
'<tr><td>2</td><td>[float]</td><td>123.45</td></tr>'.
'<td colspan="2">[NULL]</td>'.
Var_Dump ::display ($GLOBALS['array'],TRUE )
/*=============================*/
/* Test "HTML4_Table" Renderer */
/*=============================*/
function test_renderer_html4_table () {
Var_Dump ::displayInit (array ('display_mode'=> 'HTML4_Table'));
'<table border="0" cellpadding="1" cellspacing="0" bgcolor="black"><tr><td>'.
'<table border="0" cellpadding="4" cellspacing="0" width="100%">'.
'<caption style="color:white;background:#339900;">array(3)</caption>'.
'<tr valign="top" bgcolor="#F8F8F8">'.
'<td bgcolor="#CCCCCC"><b>key1</b></td>'.
'<td><font color="#000000">string(44)</font></td>'.
'<td><font color="#006600">The quick brown<br />'. "\n". 'fox jumped over<br />'. "\n". 'the lazy dog</font></td>'.
'</tr><tr valign="top" bgcolor="#E8E8E8">'.
'<td bgcolor="#CCCCCC"><b>key2</b></td>'.
'<table border="0" cellpadding="1" cellspacing="0" bgcolor="black"><tr><td>'.
'<table border="0" cellpadding="4" cellspacing="0" width="100%">'.
'<caption style="color:white;background:#339900;">&array(3)</caption>'.
'<tr valign="top" bgcolor="#F8F8F8">'.
'<td bgcolor="#CCCCCC"><b>0</b></td>'.
'<td><font color="#000000">bool</font></td>'.
'<td><font color="#006600">true</font></td>'.
'</tr><tr valign="top" bgcolor="#E8E8E8">'.
'<td bgcolor="#CCCCCC"><b>1</b></td>'.
'<td><font color="#000000">int</font></td>'.
'<td><font color="#006600">123</font></td>'.
'</tr><tr valign="top" bgcolor="#F8F8F8">'.
'<td bgcolor="#CCCCCC"><b>2</b></td>'.
'<td><font color="#000000">float</font></td>'.
'<td><font color="#006600">123.45</font></td>'.
'</table></td></tr></table>'.
'</tr><tr valign="top" bgcolor="#F8F8F8">'.
'<td bgcolor="#CCCCCC"><b>key3</b></td>'.
'<td colspan="2"><font color="#000000">NULL</font></td>'.
'</table></td></tr></table>',
Var_Dump ::display ($GLOBALS['array'],TRUE )
/*=============================*/
/* Test "XHTML_Table" Renderer */
/*=============================*/
function test_renderer_xhtml_table () {
Var_Dump ::displayInit (array ('display_mode'=> 'XHTML_Table'));
'<table class="var_dump">'.
'<caption>array(3)</caption>'.
'<td><i>string(44)</i></td>'.
'<td>The quick brown<br />'. "\n". 'fox jumped over<br />'. "\n". 'the lazy dog</td>'.
'<table class="var_dump">'.
'<caption>&array(3)</caption>'.
'<tr><th>0</th><td><i>bool</i></td><td>true</td></tr>'.
'<tr class="alt"><th>1</th><td><i>int</i></td><td>123</td></tr>'.
'<tr><th>2</th><td><i>float</i></td><td>123.45</td></tr>'.
'<td colspan="2"><i>NULL</i></td>'.
Var_Dump ::display ($GLOBALS['array'],TRUE )
/*=====================*/
/* Test "XML" Renderer */
/*=====================*/
function test_renderer_xml () {
Var_Dump ::displayInit (array ('display_mode'=> 'XML'));
'<group caption="array(3)">'. "\n".
' <type>string(44)</type>'. "\n".
' <value>The quick brown'. "\n".
'the lazy dog</value>'. "\n".
' <type>group</type>'. "\n".
' <group caption="&array(3)">'. "\n".
' <type>bool</type>'. "\n".
' <value>true</value>'. "\n".
' <type>int</type>'. "\n".
' <value>123</value>'. "\n".
' <type>float</type>'. "\n".
' <value>123.45</value>'. "\n".
' <type>NULL</type>'. "\n".
Var_Dump ::display ($GLOBALS['array'],TRUE )
/*===================================*/
/* Test Text Renderer : Compact mode */
/*===================================*/
function test_renderer_text_compact () {
array ('display_mode'=> 'Text'),
' key-1 => string(44) The quick brown fox jumped over the lazy dog'. "\n".
' key-2 => array(2) {'. "\n".
' long-key => &array(3) {'. "\n".
' 0 => string(4) John'. "\n".
' 11 => string(4) Jack'. "\n".
' 127 => string(4) Bill'. "\n".
' long-key-3 => int 234'. "\n".
Var_Dump ::display ($GLOBALS['array2'],TRUE )
/*==================================*/
/* Test Text Renderer : Normal mode */
/*==================================*/
function test_renderer_text_normal () {
array ('display_mode'=> 'Text'),
' key-1 => string(44) The quick brown fox jumped over the lazy dog'. "\n".
' key-2 => array(2) {'. "\n".
' long-key => &array(3) {'. "\n".
' 0 => string(4) John'. "\n".
' 11 => string(4) Jack'. "\n".
' 127 => string(4) Bill'. "\n".
' long-key-3 => int 234'. "\n".
Var_Dump ::display ($GLOBALS['array2'],TRUE )
/*================================*/
/* Test Text Renderer : Wide mode */
/*================================*/
function test_renderer_text_wide () {
array ('display_mode'=> 'Text'),
' key-1 => string(44) The quick brown fox jumped over the lazy dog'. "\n".
' key-2 => array(2) {'. "\n".
' long-key => &array(3) {'. "\n".
' 0 => string(4) John'. "\n".
' 11 => string(4) Jack'. "\n".
' 127 => string(4) Bill'. "\n".
' long-key-3 => int 234'. "\n".
Var_Dump ::display ($GLOBALS['array2'],TRUE )
/*==================================*/
/* Bug #490 Recursions not managed. */
/*==================================*/
function test_bug_490 () {
'object(parent)(2) {'. "\n".
' myChild => object(child)(1) {'. "\n".
' myParent => &object(parent)(2) {'. "\n".
' myChild => object(child)(1) {'. "\n".
' myParent => &object(parent)(2) {'. "\n".
' myChild => *RECURSION*'. "\n".
' myName => string(6) parent'. "\n".
' myName => string(6) parent'. "\n".
' myName => string(6) parent'. "\n".
$this->vd->toString (new parent ())
/*============================================================================*/
/* Bug #1321 Numeric zero values in array or object attributes are not shown. */
/*============================================================================*/
function test_bug_1321 () {
'object(zero)(2) {'. "\n".
$this->vd->toString (new zero ())
$this->vd->toString (array (0 ,0.0 ))
/*============================*/
/* Classes used by test Cases */
/*============================*/
var $key1 = "The quick brown\nfox jumped over\nthe lazy dog";
var $key2 = array (TRUE , 123 , 123.45 );
$this->myChild = new child ($this);
$this->myName = 'parent';
function child (&$parent) {
$this->myParent = & $parent;
$this->recursion = new recursion ();
$linkedArray=array (TRUE , 123 , 123.45 );
'key1' => 'The quick brown'. "\n". 'fox jumped over'. "\n". 'the lazy dog',
'key2' => & $linkedArray,
$linkedArray2=array (0=> 'John', 11=> 'Jack', 127=> 'Bill');
'key-1' => 'The quick brown fox jumped over the lazy dog',
'long-key' => & $linkedArray2,
$suite = new PHPUnit_TestSuite ("Var_DumpTest");
$result = PHPUnit ::run ($suite);
Documentation generated on Mon, 11 Mar 2019 13:51:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|