Source for file dumper.php
Documentation is available at dumper.php
* base include file for SimpleTest
* @version $Id: dumper.php 1723 2008-04-08 00:34:10Z lastcraft $
* Displays variables as text and does diffs.
* Renders a variable in a shorter form than print_r().
* @param mixed $value Variable to render as a string.
* @return string Human readable string form.
return "Boolean: " .
($value ?
"true" :
"false");
return "Array: " .
count($value) .
" items";
return "String: " .
$this->clipString($value, 200);
* Gets the string representation of a type.
* @param mixed $value Variable to check against.
* Creates a human readable description of the
* difference between two variables. Uses a
* @param mixed $first First variable.
* @param mixed $second Value to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Description of difference.
if (! $this->_isTypeMatch($first, $second)) {
return "with type mismatch as [" .
$this->describeValue($first) .
if ($type ==
"Unknown") {
return "with unknown type";
$method =
'_describe' .
$type .
'Difference';
return $this->$method($first, $second, $identical);
* Tests to see if types match.
* @param mixed $first First variable.
* @param mixed $second Value to compare with.
* @return boolean True if matches.
function _isTypeMatch($first, $second) {
* Clips a string to a maximum length.
* @param string $value String to truncate.
* @param integer $size Minimum string size to show.
* @param integer $position Centre of string section.
* @return string Shortened version.
function clipString($value, $size, $position =
0) {
$position =
min($position, $length);
$start =
($size/
2 >
$position ?
0 :
$position -
$size/
2);
if ($start +
$size >
$length) {
$start =
$length -
$size;
$value =
substr($value, $start, $size);
return ($start >
0 ?
"..." :
"") .
$value .
($start +
$size <
$length ?
"..." :
"");
* Creates a human readable description of the
* difference between two variables. The minimal
* @param null $first First value.
* @param mixed $second Value to compare with.
* @return string Human readable description.
function _describeGenericDifference($first, $second) {
* Creates a human readable description of the
* difference between a null and another variable.
* @param null $first First null.
* @param mixed $second Null to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Human readable description.
function _describeNullDifference($first, $second, $identical) {
return $this->_describeGenericDifference($first, $second);
* Creates a human readable description of the
* difference between a boolean and another variable.
* @param boolean $first First boolean.
* @param mixed $second Boolean to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Human readable description.
function _describeBooleanDifference($first, $second, $identical) {
return $this->_describeGenericDifference($first, $second);
* Creates a human readable description of the
* difference between a string and another variable.
* @param string $first First string.
* @param mixed $second String to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Human readable description.
function _describeStringDifference($first, $second, $identical) {
return $this->_describeGenericDifference($first, $second);
$position =
$this->_stringDiffersAt($first, $second);
$message =
"at character $position";
$this->clipString($first, 200, $position) .
"] and [" .
* Creates a human readable description of the
* difference between an integer and another variable.
* @param integer $first First number.
* @param mixed $second Number to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Human readable description.
function _describeIntegerDifference($first, $second, $identical) {
return $this->_describeGenericDifference($first, $second);
* Creates a human readable description of the
* difference between two floating point numbers.
* @param float $first First float.
* @param mixed $second Float to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Human readable description.
function _describeFloatDifference($first, $second, $identical) {
return $this->_describeGenericDifference($first, $second);
* Creates a human readable description of the
* difference between two arrays.
* @param array $first First array.
* @param mixed $second Array to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Human readable description.
function _describeArrayDifference($first, $second, $identical) {
return $this->_describeGenericDifference($first, $second);
if (! $this->_isMatchingKeys($first, $second, $identical)) {
if ($identical &&
($first[$key] ===
$second[$key])) {
if (! $identical &&
($first[$key] ==
$second[$key])) {
* Compares two arrays to see if their key lists match.
* For an identical match, the ordering and types of the keys
* @param array $first First array.
* @param array $second Array to compare with.
* @param boolean $identical If true then type anomolies count.
* @return boolean True if matching.
function _isMatchingKeys($first, $second, $identical) {
return ($first_keys ===
$second_keys);
return ($first_keys ==
$second_keys);
* Creates a human readable description of the
* difference between a resource and another variable.
* @param resource $first First resource.
* @param mixed $second Resource to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Human readable description.
function _describeResourceDifference($first, $second, $identical) {
return $this->_describeGenericDifference($first, $second);
* Creates a human readable description of the
* difference between two objects.
* @param object $first First object.
* @param mixed $second Object to compare with.
* @param boolean $identical If true then type anomolies count.
* @return string Human readable description.
function _describeObjectDifference($first, $second, $identical) {
return $this->_describeGenericDifference($first, $second);
return $this->_describeArrayDifference(
* Find the first character position that differs
* in two strings by binary chop.
* @param string $first First string.
* @param string $second String to compare with.
* @return integer Position of first differing
function _stringDiffersAt($first, $second) {
if (! $first ||
! $second) {
list
($first, $second) =
array($second, $first);
$step = (integer)
(($step +
1) /
2);
if (strncmp($first, $second, $position +
$step) ==
0) {
* Sends a formatted dump of a variable to a string.
* @param mixed $variable Variable to display.
* @return string Output from print_r().
function dump($variable) {
Documentation generated on Sun, 04 May 2008 09:21:28 -0500 by phpDocumentor 1.3.0