protected function PHPUnit_Framework_TestCase::dataToString

@since Method available since Release 3.2.1

Parameters

mixed $data:

Return value

string

1 call to PHPUnit_Framework_TestCase::dataToString()
PHPUnit_Framework_TestCase::getDataSetAsString in drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php
Gets the data set description of a TestCase.

File

drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php, line 1660

Class

PHPUnit_Framework_TestCase
A TestCase defines the fixture to run multiple tests.

Code

protected function dataToString($data) {
  $result = array();

  // There seems to be no other way to check arrays for recursion
  // http://www.php.net/manual/en/language.types.array.php#73936
  preg_match_all('/\\n            \\[(\\w+)\\] => Array\\s+\\*RECURSION\\*/', print_r($data, TRUE), $matches);
  $recursiveKeys = array_unique($matches[1]);

  // Convert to valid array keys
  // Numeric integer strings are automatically converted to integers
  // by PHP
  foreach ($recursiveKeys as $key => $recursiveKey) {
    if ((string) (int) $recursiveKey === $recursiveKey) {
      $recursiveKeys[$key] = (int) $recursiveKey;
    }
  }
  foreach ($data as $key => $_data) {
    if (in_array($key, $recursiveKeys, TRUE)) {
      $result[] = '*RECURSION*';
    }
    else {
      if (is_array($_data)) {
        $result[] = 'array(' . $this
          ->dataToString($_data) . ')';
      }
      else {
        if (is_object($_data)) {
          $object = new ReflectionObject($_data);
          if ($object
            ->hasMethod('__toString')) {
            $result[] = (string) $_data;
          }
          else {
            $result[] = get_class($_data);
          }
        }
        else {
          if (is_resource($_data)) {
            $result[] = '<resource>';
          }
          else {
            $result[] = var_export($_data, TRUE);
          }
        }
      }
    }
  }
  return join(', ', $result);
}