Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace PHPUnit_Util_Type with SebastianBergmann\Exporter

  • Loading branch information...
commit b8b3e1fdc0312938d8ce2d7ff5958d52c865d780 1 parent a090833
@sebastianbergmann authored
Showing with 103 additions and 791 deletions.
  1. +2 −0  .travis.yml
  2. +1 −1  PHPUnit/Autoload.php
  3. +1 −0  PHPUnit/Autoload.php.in
  4. +9 −0 PHPUnit/Framework/Comparator.php
  5. +12 −12 PHPUnit/Framework/Comparator/Array.php
  6. +2 −2 PHPUnit/Framework/Comparator/Numeric.php
  7. +11 −16 PHPUnit/Framework/Comparator/Object.php
  8. +2 −2 PHPUnit/Framework/Comparator/Resource.php
  9. +4 −4 PHPUnit/Framework/Comparator/Scalar.php
  10. +4 −4 PHPUnit/Framework/Comparator/SplObjectStorage.php
  11. +1 −1  PHPUnit/Framework/Comparator/Type.php
  12. +9 −1 PHPUnit/Framework/Constraint.php
  13. +2 −1  PHPUnit/Framework/Constraint/ArrayHasKey.php
  14. +2 −0  PHPUnit/Framework/Constraint/Callback.php
  15. +1 −0  PHPUnit/Framework/Constraint/ClassHasAttribute.php
  16. +1 −0  PHPUnit/Framework/Constraint/Composite.php
  17. +1 −0  PHPUnit/Framework/Constraint/Count.php
  18. +1 −0  PHPUnit/Framework/Constraint/Exception.php
  19. +3 −2 PHPUnit/Framework/Constraint/ExceptionCode.php
  20. +1 −0  PHPUnit/Framework/Constraint/ExceptionMessage.php
  21. +2 −1  PHPUnit/Framework/Constraint/GreaterThan.php
  22. +3 −1 PHPUnit/Framework/Constraint/IsEqual.php
  23. +2 −1  PHPUnit/Framework/Constraint/IsIdentical.php
  24. +2 −1  PHPUnit/Framework/Constraint/IsInstanceOf.php
  25. +2 −0  PHPUnit/Framework/Constraint/IsType.php
  26. +1 −0  PHPUnit/Framework/Constraint/JsonMatches.php
  27. +2 −1  PHPUnit/Framework/Constraint/LessThan.php
  28. +2 −0  PHPUnit/Framework/Constraint/Not.php
  29. +1 −0  PHPUnit/Framework/Constraint/PCREMatch.php
  30. +1 −0  PHPUnit/Framework/Constraint/SameSize.php
  31. +2 −0  PHPUnit/Framework/Constraint/StringContains.php
  32. +1 −0  PHPUnit/Framework/Constraint/StringEndsWith.php
  33. +4 −1 PHPUnit/Framework/Constraint/StringMatches.php
  34. +1 −0  PHPUnit/Framework/Constraint/StringStartsWith.php
  35. +3 −1 PHPUnit/Framework/Constraint/TraversableContains.php
  36. +2 −0  PHPUnit/Framework/Constraint/TraversableContainsOnly.php
  37. +1 −0  PHPUnit/Util/GlobalState.php
  38. +0 −224 PHPUnit/Util/Type.php
  39. +0 −201 PHPUnit/Util/Type/ExportContext.php
  40. +0 −310 Tests/Util/TypeTest.php
  41. +1 −0  composer.json
  42. +0 −3  package.xml
View
2  .travis.yml
@@ -16,8 +16,10 @@ before_script:
- git clone --branch=master --depth=100 --quiet git://github.com/sebastianbergmann/phpunit-mock-objects.git vendor/phpunit-mock-objects
- git clone --branch=master --depth=100 --quiet git://github.com/sebastianbergmann/php-timer.git vendor/php-timer
- git clone --branch=master --depth=100 --quiet git://github.com/sebastianbergmann/diff.git vendor/diff
+ - git clone --branch=master --depth=100 --quiet git://github.com/sebastianbergmann/exporter.git vendor/exporter
- git clone --branch=master --depth=100 --quiet git://github.com/sebastianbergmann/version.git vendor/version
- ln -s ~/build/sebastianbergmann/phpunit/vendor/diff/src ~/build/sebastianbergmann/phpunit/vendor/SebastianBergmann/Diff
+ - ln -s ~/build/sebastianbergmann/phpunit/vendor/diff/src ~/build/sebastianbergmann/phpunit/vendor/SebastianBergmann/Exporter
- ln -s ~/build/sebastianbergmann/phpunit/vendor/version/src ~/build/sebastianbergmann/phpunit/vendor/SebastianBergmann/Version
- git clone --branch=master --depth=100 --quiet git://github.com/pear/pear-core.git vendor/pear-core
- git clone --branch=trunk --depth=100 --quiet git://github.com/pear/Console_Getopt.git vendor/console-getopt
View
2  PHPUnit/Autoload.php
@@ -48,6 +48,7 @@
require_once 'PHPUnit/Framework/MockObject/Autoload.php';
require_once 'Text/Template/Autoload.php';
require_once 'SebastianBergmann/Diff/autoload.php';
+require_once 'SebastianBergmann/Exporter/autoload.php';
require_once 'SebastianBergmann/Version/autoload.php';
spl_autoload_register(
@@ -180,7 +181,6 @@ function ($class)
'phpunit_util_testdox_resultprinter_text' => '/Util/TestDox/ResultPrinter/Text.php',
'phpunit_util_testsuiteiterator' => '/Util/TestSuiteIterator.php',
'phpunit_util_type' => '/Util/Type.php',
- 'phpunit_util_type_exportcontext' => '/Util/Type/ExportContext.php',
'phpunit_util_xml' => '/Util/XML.php'
);
View
1  PHPUnit/Autoload.php.in
@@ -48,6 +48,7 @@ require_once 'PHP/Timer/Autoload.php';
require_once 'PHPUnit/Framework/MockObject/Autoload.php';
require_once 'Text/Template/Autoload.php';
require_once 'SebastianBergmann/Diff/autoload.php';
+require_once 'SebastianBergmann/Exporter/autoload.php';
require_once 'SebastianBergmann/Version/autoload.php';
spl_autoload_register(
View
9 PHPUnit/Framework/Comparator.php
@@ -43,6 +43,8 @@
* @since File available since Release 3.6.0
*/
+use SebastianBergmann\Exporter\Exporter;
+
/**
* Abstract base class for comparators which compare values for equality.
*
@@ -61,6 +63,13 @@
*/
protected $factory;
+ protected $exporter;
+
+ public function __construct()
+ {
+ $this->exporter = new Exporter;
+ }
+
/**
* @param PHPUnit_Framework_ComparatorFactory $factory
*/
View
24 PHPUnit/Framework/Comparator/Array.php
@@ -101,8 +101,8 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
$expString .= sprintf(
" %s => %s\n",
- PHPUnit_Util_Type::export($key),
- PHPUnit_Util_Type::shortenedExport($value)
+ $this->exporter->export($key),
+ $this->exporter->shortenedExport($value)
);
$equal = FALSE;
continue;
@@ -113,14 +113,14 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
$expString .= sprintf(
" %s => %s\n",
- PHPUnit_Util_Type::export($key),
- PHPUnit_Util_Type::shortenedExport($value)
+ $this->exporter->export($key),
+ $this->exporter->shortenedExport($value)
);
$actString .= sprintf(
" %s => %s\n",
- PHPUnit_Util_Type::export($key),
- PHPUnit_Util_Type::shortenedExport($actual[$key])
+ $this->exporter->export($key),
+ $this->exporter->shortenedExport($actual[$key])
);
}
@@ -128,18 +128,18 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
$expString .= sprintf(
" %s => %s\n",
- PHPUnit_Util_Type::export($key),
+ $this->exporter->export($key),
$e->getExpectedAsString()
? $this->indent($e->getExpectedAsString())
- : PHPUnit_Util_Type::shortenedExport($e->getExpected())
+ : $this->exporter->shortenedExport($e->getExpected())
);
$actString .= sprintf(
" %s => %s\n",
- PHPUnit_Util_Type::export($key),
+ $this->exporter->export($key),
$e->getActualAsString()
? $this->indent($e->getActualAsString())
- : PHPUnit_Util_Type::shortenedExport($e->getActual())
+ : $this->exporter->shortenedExport($e->getActual())
);
$equal = FALSE;
}
@@ -149,8 +149,8 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
$actString .= sprintf(
" %s => %s\n",
- PHPUnit_Util_Type::export($key),
- PHPUnit_Util_Type::shortenedExport($value)
+ $this->exporter->export($key),
+ $this->exporter->shortenedExport($value)
);
$equal = FALSE;
}
View
4 PHPUnit/Framework/Comparator/Numeric.php
@@ -103,8 +103,8 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
sprintf(
'Failed asserting that %s matches expected %s.',
- PHPUnit_Util_Type::export($actual),
- PHPUnit_Util_Type::export($expected)
+ $this->exporter->export($actual),
+ $this->exporter->export($expected)
)
);
}
View
27 PHPUnit/Framework/Comparator/Object.php
@@ -89,13 +89,13 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
throw new PHPUnit_Framework_ComparisonFailure(
$expected,
$actual,
- PHPUnit_Util_Type::export($expected),
- PHPUnit_Util_Type::export($actual),
+ $this->exporter->export($expected),
+ $this->exporter->export($actual),
FALSE,
sprintf(
'%s is not instance of expected class "%s".',
- PHPUnit_Util_Type::export($actual),
+ $this->exporter->export($actual),
get_class($expected)
)
);
@@ -114,7 +114,14 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
// CAUTION: this conditional clause is not tested
if ($actual !== $expected) {
try {
- parent::assertEquals($this->toArray($expected), $this->toArray($actual), $delta, $canonicalize, $ignoreCase, $processed);
+ parent::assertEquals(
+ $this->exporter->toArray($expected),
+ $this->exporter->toArray($actual),
+ $delta,
+ $canonicalize,
+ $ignoreCase,
+ $processed
+ );
}
catch (PHPUnit_Framework_ComparisonFailure $e) {
@@ -130,16 +137,4 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
}
}
}
-
- /**
- * Converts an object to an array containing all of its private, protected
- * and public properties.
- *
- * @param object $object
- * @return array
- */
- protected function toArray($object)
- {
- return PHPUnit_Util_Type::toArray($object);
- }
}
View
4 PHPUnit/Framework/Comparator/Resource.php
@@ -89,8 +89,8 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
throw new PHPUnit_Framework_ComparisonFailure(
$expected,
$actual,
- PHPUnit_Util_Type::export($expected),
- PHPUnit_Util_Type::export($actual)
+ $this->exporter->export($expected),
+ $this->exporter->export($actual)
);
}
}
View
8 PHPUnit/Framework/Comparator/Scalar.php
@@ -110,8 +110,8 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
throw new PHPUnit_Framework_ComparisonFailure(
$expected,
$actual,
- PHPUnit_Util_Type::export($expected),
- PHPUnit_Util_Type::export($actual),
+ $this->exporter->export($expected),
+ $this->exporter->export($actual),
FALSE,
'Failed asserting that two strings are equal.'
);
@@ -127,8 +127,8 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
sprintf(
'Failed asserting that %s matches expected %s.',
- PHPUnit_Util_Type::export($actual),
- PHPUnit_Util_Type::export($expected)
+ $this->exporter->export($actual),
+ $this->exporter->export($expected)
)
);
}
View
8 PHPUnit/Framework/Comparator/SplObjectStorage.php
@@ -90,8 +90,8 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
throw new PHPUnit_Framework_ComparisonFailure(
$expected,
$actual,
- PHPUnit_Util_Type::export($expected),
- PHPUnit_Util_Type::export($actual),
+ $this->exporter->export($expected),
+ $this->exporter->export($actual),
FALSE,
'Failed asserting that two objects are equal.'
);
@@ -103,8 +103,8 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
throw new PHPUnit_Framework_ComparisonFailure(
$expected,
$actual,
- PHPUnit_Util_Type::export($expected),
- PHPUnit_Util_Type::export($actual),
+ $this->exporter->export($expected),
+ $this->exporter->export($actual),
FALSE,
'Failed asserting that two objects are equal.'
);
View
2  PHPUnit/Framework/Comparator/Type.php
@@ -96,7 +96,7 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL
sprintf(
'%s does not match expected type "%s".',
- PHPUnit_Util_Type::shortenedExport($actual),
+ $this->exporter->shortenedExport($actual),
gettype($expected)
)
);
View
10 PHPUnit/Framework/Constraint.php
@@ -44,6 +44,8 @@
* @since File available since Release 3.0.0
*/
+use SebastianBergmann\Exporter\Exporter;
+
/**
* Abstract base class for constraints. which are placed upon any value.
*
@@ -58,6 +60,12 @@
*/
abstract class PHPUnit_Framework_Constraint implements Countable, PHPUnit_Framework_SelfDescribing
{
+ protected $exporter;
+
+ public function __construct()
+ {
+ $this->exporter = new Exporter;
+ }
/**
* Evaluates the constraint for parameter $other
@@ -175,6 +183,6 @@ protected function additionalFailureDescription($other)
*/
protected function failureDescription($other)
{
- return PHPUnit_Util_Type::export($other) . ' ' . $this->toString();
+ return $this->exporter->export($other) . ' ' . $this->toString();
}
}
View
3  PHPUnit/Framework/Constraint/ArrayHasKey.php
@@ -73,6 +73,7 @@ class PHPUnit_Framework_Constraint_ArrayHasKey extends PHPUnit_Framework_Constra
*/
public function __construct($key)
{
+ parent::__construct();
$this->key = $key;
}
@@ -95,7 +96,7 @@ protected function matches($other)
*/
public function toString()
{
- return 'has the key ' . PHPUnit_Util_Type::export($this->key);
+ return 'has the key ' . $this->exporter->export($this->key);
}
/**
View
2  PHPUnit/Framework/Constraint/Callback.php
@@ -63,6 +63,8 @@ class PHPUnit_Framework_Constraint_Callback extends PHPUnit_Framework_Constraint
*/
public function __construct(callable $callback)
{
+ parent::__construct();
+
$this->callback = $callback;
}
View
1  PHPUnit/Framework/Constraint/ClassHasAttribute.php
@@ -71,6 +71,7 @@ class PHPUnit_Framework_Constraint_ClassHasAttribute extends PHPUnit_Framework_C
*/
public function __construct($attributeName)
{
+ parent::__construct();
$this->attributeName = $attributeName;
}
View
1  PHPUnit/Framework/Constraint/Composite.php
@@ -68,6 +68,7 @@
*/
public function __construct(PHPUnit_Framework_Constraint $innerConstraint)
{
+ parent::__construct();
$this->innerConstraint = $innerConstraint;
}
View
1  PHPUnit/Framework/Constraint/Count.php
@@ -68,6 +68,7 @@ class PHPUnit_Framework_Constraint_Count extends PHPUnit_Framework_Constraint
*/
public function __construct($expected)
{
+ parent::__construct();
$this->expectedCount = $expected;
}
View
1  PHPUnit/Framework/Constraint/Exception.php
@@ -66,6 +66,7 @@ class PHPUnit_Framework_Constraint_Exception extends PHPUnit_Framework_Constrain
*/
public function __construct($className)
{
+ parent::__construct();
$this->className = $className;
}
View
5 PHPUnit/Framework/Constraint/ExceptionCode.php
@@ -66,6 +66,7 @@ class PHPUnit_Framework_Constraint_ExceptionCode extends PHPUnit_Framework_Const
*/
public function __construct($expected)
{
+ parent::__construct();
$this->expectedCode = $expected;
}
@@ -94,8 +95,8 @@ protected function failureDescription($other)
{
return sprintf(
'%s is equal to expected exception code %s',
- PHPUnit_Util_Type::export($other->getCode()),
- PHPUnit_Util_Type::export($this->expectedCode)
+ $this->exporter->export($other->getCode()),
+ $this->exporter->export($this->expectedCode)
);
}
View
1  PHPUnit/Framework/Constraint/ExceptionMessage.php
@@ -66,6 +66,7 @@ class PHPUnit_Framework_Constraint_ExceptionMessage extends PHPUnit_Framework_Co
*/
public function __construct($expected)
{
+ parent::__construct();
$this->expectedMessage = $expected;
}
View
3  PHPUnit/Framework/Constraint/GreaterThan.php
@@ -69,6 +69,7 @@ class PHPUnit_Framework_Constraint_GreaterThan extends PHPUnit_Framework_Constra
*/
public function __construct($value)
{
+ parent::__construct();
$this->value = $value;
}
@@ -91,6 +92,6 @@ protected function matches($other)
*/
public function toString()
{
- return 'is greater than ' . PHPUnit_Util_Type::export($this->value);
+ return 'is greater than ' . $this->exporter->export($this->value);
}
}
View
4 PHPUnit/Framework/Constraint/IsEqual.php
@@ -105,6 +105,8 @@ class PHPUnit_Framework_Constraint_IsEqual extends PHPUnit_Framework_Constraint
*/
public function __construct($value, $delta = 0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE)
{
+ parent::__construct();
+
if (!is_numeric($delta)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'numeric');
}
@@ -207,7 +209,7 @@ public function toString()
return sprintf(
'is equal to %s%s',
- PHPUnit_Util_Type::export($this->value),
+ $this->exporter->export($this->value),
$delta
);
}
View
3  PHPUnit/Framework/Constraint/IsIdentical.php
@@ -81,6 +81,7 @@ class PHPUnit_Framework_Constraint_IsIdentical extends PHPUnit_Framework_Constra
*/
public function __construct($value)
{
+ parent::__construct();
$this->value = $value;
}
@@ -167,7 +168,7 @@ public function toString()
get_class($this->value) . '"';
} else {
return 'is identical to ' .
- PHPUnit_Util_Type::export($this->value);
+ $this->exporter->export($this->value);
}
}
}
View
3  PHPUnit/Framework/Constraint/IsInstanceOf.php
@@ -71,6 +71,7 @@ class PHPUnit_Framework_Constraint_IsInstanceOf extends PHPUnit_Framework_Constr
*/
public function __construct($className)
{
+ parent::__construct();
$this->className = $className;
}
@@ -99,7 +100,7 @@ protected function failureDescription($other)
{
return sprintf(
'%s is an instance of %s "%s"',
- PHPUnit_Util_Type::shortenedExport($other),
+ $this->exporter->shortenedExport($other),
$this->getType(),
$this->className
);
View
2  PHPUnit/Framework/Constraint/IsType.php
@@ -103,6 +103,8 @@ class PHPUnit_Framework_Constraint_IsType extends PHPUnit_Framework_Constraint
*/
public function __construct($type)
{
+ parent::__construct();
+
if (!isset($this->types[$type])) {
throw new PHPUnit_Framework_Exception(
sprintf(
View
1  PHPUnit/Framework/Constraint/JsonMatches.php
@@ -68,6 +68,7 @@ class PHPUnit_Framework_Constraint_JsonMatches extends PHPUnit_Framework_Constra
*/
public function __construct($value)
{
+ parent::__construct();
$this->value = $value;
}
View
3  PHPUnit/Framework/Constraint/LessThan.php
@@ -69,6 +69,7 @@ class PHPUnit_Framework_Constraint_LessThan extends PHPUnit_Framework_Constraint
*/
public function __construct($value)
{
+ parent::__construct();
$this->value = $value;
}
@@ -91,6 +92,6 @@ protected function matches($other)
*/
public function toString()
{
- return 'is less than ' . PHPUnit_Util_Type::export($this->value);
+ return 'is less than ' . $this->exporter->export($this->value);
}
}
View
2  PHPUnit/Framework/Constraint/Not.php
@@ -69,6 +69,8 @@ class PHPUnit_Framework_Constraint_Not extends PHPUnit_Framework_Constraint
*/
public function __construct($constraint)
{
+ parent::__construct();
+
if (!($constraint instanceof PHPUnit_Framework_Constraint)) {
$constraint = new PHPUnit_Framework_Constraint_IsEqual($constraint);
}
View
1  PHPUnit/Framework/Constraint/PCREMatch.php
@@ -74,6 +74,7 @@ class PHPUnit_Framework_Constraint_PCREMatch extends PHPUnit_Framework_Constrain
*/
public function __construct($pattern)
{
+ parent::__construct();
$this->pattern = $pattern;
}
View
1  PHPUnit/Framework/Constraint/SameSize.php
@@ -68,6 +68,7 @@ class PHPUnit_Framework_Constraint_SameSize extends PHPUnit_Framework_Constraint
*/
public function __construct($expected)
{
+ parent::__construct();
$this->expectedCount = $this->getCountOf($expected);
}
}
View
2  PHPUnit/Framework/Constraint/StringContains.php
@@ -80,6 +80,8 @@ class PHPUnit_Framework_Constraint_StringContains extends PHPUnit_Framework_Cons
*/
public function __construct($string, $ignoreCase = FALSE)
{
+ parent::__construct();
+
$this->string = $string;
$this->ignoreCase = $ignoreCase;
}
View
1  PHPUnit/Framework/Constraint/StringEndsWith.php
@@ -69,6 +69,7 @@ class PHPUnit_Framework_Constraint_StringEndsWith extends PHPUnit_Framework_Cons
*/
public function __construct($suffix)
{
+ parent::__construct();
$this->suffix = $suffix;
}
View
5 PHPUnit/Framework/Constraint/StringMatches.php
@@ -70,10 +70,13 @@ class PHPUnit_Framework_Constraint_StringMatches extends PHPUnit_Framework_Const
*/
public function __construct($string)
{
+ parent::__construct($string);
+
$this->pattern = $this->createPatternFromFormat(
preg_replace('/\r\n/', "\n", $string)
);
- $this->string = $string;
+
+ $this->string = $string;
}
protected function failureDescription($other)
View
1  PHPUnit/Framework/Constraint/StringStartsWith.php
@@ -69,6 +69,7 @@ class PHPUnit_Framework_Constraint_StringStartsWith extends PHPUnit_Framework_Co
*/
public function __construct($prefix)
{
+ parent::__construct();
$this->prefix = $prefix;
}
View
4 PHPUnit/Framework/Constraint/TraversableContains.php
@@ -76,6 +76,8 @@ class PHPUnit_Framework_Constraint_TraversableContains extends PHPUnit_Framework
*/
public function __construct($value, $checkForObjectIdentity = TRUE)
{
+ parent::__construct();
+
if (!is_bool($checkForObjectIdentity)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'boolean');
}
@@ -127,7 +129,7 @@ public function toString()
if (is_string($this->value) && strpos($this->value, "\n") !== FALSE) {
return 'contains "' . $this->value . '"';
} else {
- return 'contains ' . PHPUnit_Util_Type::export($this->value);
+ return 'contains ' . $this->exporter->export($this->value);
}
}
View
2  PHPUnit/Framework/Constraint/TraversableContainsOnly.php
@@ -75,6 +75,8 @@ class PHPUnit_Framework_Constraint_TraversableContainsOnly extends PHPUnit_Frame
*/
public function __construct($type, $isNativeType = TRUE)
{
+ parent::__construct();
+
if ($isNativeType) {
$this->constraint = new PHPUnit_Framework_Constraint_IsType($type);
} else {
View
1  PHPUnit/Util/GlobalState.php
@@ -411,6 +411,7 @@ public static function phpunitFiles()
self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_Story_TestCase', 2);
self::addDirectoryContainingClassToPHPUnitFilesList('Text_Template');
self::addDirectoryContainingClassToPHPUnitFilesList('SebastianBergmann\Diff');
+ self::addDirectoryContainingClassToPHPUnitFilesList('SebastianBergmann\Exporter\Exporter');
self::addDirectoryContainingClassToPHPUnitFilesList('SebastianBergmann\Version');
}
View
224 PHPUnit/Util/Type.php
@@ -76,228 +76,4 @@ public static function isType($type)
)
);
}
-
- /**
- * Exports a value into a string
- *
- * The output of this method is similar to the output of print_r(), but
- * improved in various aspects:
- *
- * - NULL is rendered as "null" (instead of "")
- * - TRUE is rendered as "true" (instead of "1")
- * - FALSE is rendered as "false" (instead of "")
- * - Strings are always quoted with single quotes
- * - Carriage returns and newlines are normalized to \n
- * - Recursion and repeated rendering is treated properly
- *
- * @param mixed $value The value to export
- * @param integer $indentation The indentation level of the 2nd+ line
- * @return string
- * @since Method available since Release 3.6.0
- */
- public static function export($value, $indentation = 0)
- {
- return self::recursiveExport($value, $indentation);
- }
-
- /**
- * Recursive implementation of export
- *
- * @param mixed $value The value to export
- * @param integer $indentation The indentation level of the 2nd+ line
- * @param PHPUnit_Util_Type_ExportContext $processed Contains all objects
- * and arrays that have
- * previously been
- * rendered
- * @return string
- * @since Method available since Release 3.6.0
- * @see PHPUnit_Util_Type::export
- */
- protected static function recursiveExport(&$value, $indentation, $processed = null)
- {
- if ($value === NULL) {
- return 'null';
- }
-
- if ($value === TRUE) {
- return 'true';
- }
-
- if ($value === FALSE) {
- return 'false';
- }
-
- if (is_float($value) && floatval(intval($value)) === $value) {
- return "$value.0";
- }
-
- if (is_resource($value)) {
- return sprintf(
- 'resource(%d) of type (%s)',
- $value,
- get_resource_type($value)
- );
- }
-
- if (is_string($value)) {
- // Match for most non printable chars somewhat taking multibyte chars into account
- if (preg_match('/[^\x09-\x0d\x20-\xff]/', $value)) {
- return 'Binary String: 0x' . bin2hex($value);
- }
-
- return "'" .
- str_replace(array("\r\n", "\n\r", "\r"), array("\n", "\n", "\n"), $value) .
- "'";
- }
-
- $whitespace = str_repeat(' ', 4 * $indentation);
-
- if (!$processed) {
- $processed = new PHPUnit_Util_Type_ExportContext;
- }
-
- if (is_array($value)) {
- if (($key = $processed->contains($value)) !== false) {
- return "Array &$key";
- }
-
- $key = $processed->add($value);
- if (count($value) > 0) {
- $output = "Array &$key (\n";
-
- foreach ($value as $k => $v) {
- $ek = self::export($k);
- $output .= "$whitespace $ek => ".self::recursiveExport($value[$k], $indentation + 1, $processed)."\n";
- }
-
- return "$output$whitespace)";
- } else {
- return "Array &$key ()";
- }
- }
-
- if (is_object($value)) {
- $class = get_class($value);
-
- if ($hash = $processed->contains($value)) {
- return "$class Object &$hash";
- }
-
- $hash = $processed->add($value);
- $array = self::toArray($value);
- if (count($array) > 0) {
- $output = "$class Object &$hash (\n";
-
- foreach ($array as $k => $v) {
- $k = self::export($k);
- $output .= "$whitespace $k => ".self::recursiveExport($v, $indentation + 1, $processed)."\n";
- }
-
- return "$output$whitespace)";
- } else {
- return "$class Object &$hash ()";
- }
-
- }
-
- return var_export($value, true);
- }
-
- /**
- * Exports a value into a single-line string
- *
- * The output of this method is similar to the output of
- * PHPUnit_Util_Type::export. This method guarantees thought that the
- * result contains now newlines.
- *
- * Newlines are replaced by the visible string '\n'. Contents of arrays
- * and objects (if any) are replaced by '...'.
- *
- * @param mixed $value The value to export
- * @param integer $indentation The indentation level of the 2nd+ line
- * @return string
- * @see PHPUnit_Util_Type::export
- */
- public static function shortenedExport($value)
- {
- if (is_string($value)) {
- return self::shortenedString($value);
- }
-
- if (is_object($value)) {
- return sprintf(
- '%s Object (%s)',
- get_class($value),
- count(self::toArray($value)) > 0 ? '...' : ''
- );
- }
-
- if (is_array($value)) {
- return sprintf(
- 'Array (%s)',
- count($value) > 0 ? '...' : ''
- );
- }
-
- return self::export($value);
- }
-
- /**
- * Shortens a string and converts all new lines to '\n'
- *
- * @param string $string The string to shorten
- * @param integer $max The maximum length for the string
- * @return string
- */
- public static function shortenedString($string, $maxLength = 40)
- {
- $string = self::export($string);
-
- if (strlen($string) > $maxLength) {
- $string = substr($string, 0, $maxLength - 10) . '...' . substr($string, -7);
- }
-
- return str_replace("\n", '\n', $string);
- }
-
- /**
- * Converts an object to an array containing all of its private, protected
- * and public properties.
- *
- * @param object $object
- * @return array
- * @since Method available since Release 3.6.0
- */
- public static function toArray($object)
- {
- $array = array();
-
- foreach ((array)$object as $key => $value) {
- // properties are transformed to keys in the following way:
-
- // private $property => "\0Classname\0property"
- // protected $property => "\0*\0property"
- // public $property => "property"
-
- if (preg_match('/^\0.+\0(.+)$/', $key, $matches)) {
- $key = $matches[1];
- }
-
- $array[$key] = $value;
- }
-
- // Some internal classes like SplObjectStorage don't work with the
- // above (fast) mechanism nor with reflection
- // Format the output similarly to print_r() in this case
- if ($object instanceof SplObjectStorage) {
- foreach ($object as $value) {
- $array[spl_object_hash($value)] = array(
- 'obj' => $value,
- 'inf' => $object->getInfo(),
- );
- }
- }
-
- return $array;
- }
}
View
201 PHPUnit/Util/Type/ExportContext.php
@@ -1,201 +0,0 @@
-<?php
-/**
- * PHPUnit
- *
- * Copyright (c) 2001-2013, Sebastian Bergmann <sebastian@phpunit.de>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * * Neither the name of Sebastian Bergmann nor the names of his
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * @package PHPUnit
- * @subpackage Util
- * @author Adam Harvey <aharvey@php.net>
- * @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
- * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
- * @link http://www.phpunit.de/
- * @since File available since Release 3.8.0
- */
-
-/**
- * A context containing previously rendered arrays and objects when recursively
- * exporting a value.
- *
- * @package PHPUnit
- * @subpackage Util
- * @author Adam Harvey <aharvey@php.net>
- * @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
- * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
- * @link http://www.phpunit.de/
- * @since Class available since Release 3.8.0
- */
-class PHPUnit_Util_Type_ExportContext {
- /**
- * Previously seen arrays.
- *
- * @var array[] $arrays
- */
- protected $arrays = array();
-
- /**
- * Previously seen objects.
- *
- * @var SplObjectStorage $objects
- */
- protected $objects;
-
- /** Initialises the context. */
- public function __construct()
- {
- $this->arrays = array();
- $this->objects = new SplObjectStorage;
- }
-
- /**
- * Adds a value to the export context.
- *
- * @param mixed $value The value to add.
- * @return mixed The ID of the stored value, either as a string or integer.
- * @throws PHPUnit_Framework_Exception Thrown if $value is not an array or
- * object.
- */
- public function add(&$value)
- {
- if (is_array($value)) {
- return $this->addArray($value);
- }
-
- else if (is_object($value)) {
- return $this->addObject($value);
- }
-
- throw new PHPUnit_Framework_Exception(
- 'Only arrays and objects are supported'
- );
- }
-
- /**
- * Checks if the given value exists within the context.
- *
- * @param mixed $value The value to check.
- * @return mixed The string or integer ID of the stored value if it has
- * already been seen, or boolean false if the value is not
- * stored.
- * @throws PHPUnit_Framework_Exception Thrown if $value is not an array or
- * object.
- */
- public function contains(&$value)
- {
- if (is_array($value)) {
- return $this->containsArray($value);
- }
-
- else if (is_object($value)) {
- return $this->containsObject($value);
- }
-
- throw new PHPUnit_Framework_Exception(
- 'Only arrays and objects are supported'
- );
- }
-
- /**
- * Stores an array within the context.
- *
- * @param array $value The value to store.
- * @return integer The internal ID of the array.
- */
- protected function addArray(array &$value)
- {
- if (($key = $this->containsArray($value)) !== false) {
- return $key;
- }
-
- $this->arrays[] = &$value;
-
- return count($this->arrays) - 1;
- }
-
- /**
- * Stores an object within the context.
- *
- * @param object $value
- * @return string The ID of the object.
- */
- protected function addObject($value)
- {
- if (!$this->objects->contains($value)) {
- $this->objects->attach($value);
- }
-
- return spl_object_hash($value);
- }
-
- /**
- * Checks if the given array exists within the context.
- *
- * @param array $value The array to check.
- * @return mixed The integer ID of the array if it exists, or boolean false
- * otherwise.
- */
- protected function containsArray(array &$value)
- {
- $keys = array_keys($this->arrays, $value, true);
- $gen = '_PHPUnit_Test_Key_' . hash('sha512', microtime(TRUE));
-
- foreach ($keys as $key) {
- $this->arrays[$key][$gen] = $gen;
-
- if (isset($value[$gen]) && $value[$gen] === $gen) {
- unset($this->arrays[$key][$gen]);
- return $key;
- }
-
- unset($this->arrays[$key][$gen]);
- }
-
- return FALSE;
- }
-
- /**
- * Checks if the given object exists within the context.
- *
- * @param object $value The object to check.
- * @return mixed The string ID of the object if it exists, or boolean false
- * otherwise.
- */
- protected function containsObject($value)
- {
- if ($this->objects->contains($value)) {
- return spl_object_hash($value);
- }
-
- return FALSE;
- }
-}
View
310 Tests/Util/TypeTest.php
@@ -1,310 +0,0 @@
-<?php
-/**
- * PHPUnit
- *
- * Copyright (c) 2001-2013, Sebastian Bergmann <sebastian@phpunit.de>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * * Neither the name of Sebastian Bergmann nor the names of his
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * @package PHPUnit
- * @author Bernhard Schussek <bschussek@2bepublished.at>
- * @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
- * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
- * @link http://www.phpunit.de/
- * @since File available since Release 3.6.0
- */
-
-require_once 'PHPUnit/Framework/TestCase.php';
-
-require_once 'PHPUnit/Util/Type.php';
-
-/**
- *
- *
- * @package PHPUnit
- * @author Bernhard Schussek <bschussek@2bepublished.at>
- * @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
- * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
- * @link http://www.phpunit.de/
- * @since Class available since Release 3.6.0
- */
-class Util_TypeTest extends PHPUnit_Framework_TestCase
-{
- /**
- * Removes spaces in front newlines
- *
- * @param string $string
- * @return string
- */
- public static function trimnl($string)
- {
- return preg_replace('/[ ]*\n/', "\n", $string);
- }
-
- public function exportProvider()
- {
- $obj2 = new stdClass;
- $obj2->foo = 'bar';
-
- $obj = new stdClass;
- //@codingStandardsIgnoreStart
- $obj->null = NULL;
- //@codingStandardsIgnoreEnd
- $obj->boolean = TRUE;
- $obj->integer = 1;
- $obj->double = 1.2;
- $obj->string = '1';
- $obj->text = "this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext";
- $obj->object = $obj2;
- $obj->objectagain = $obj2;
- $obj->array = array('foo' => 'bar');
- $obj->self = $obj;
-
- $array = array(
- 0 => 0,
- 'null' => NULL,
- 'boolean' => TRUE,
- 'integer' => 1,
- 'double' => 1.2,
- 'string' => '1',
- 'text' => "this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext",
- 'object' => $obj2,
- 'objectagain' => $obj2,
- 'array' => array('foo' => 'bar'),
- );
-
- $array['self'] = &$array;
-
- return array(
- array(NULL, 'null'),
- array(TRUE, 'true'),
- array(1, '1'),
- array(1.0, '1.0'),
- array(1.2, '1.2'),
- array(fopen('php://memory', 'r'), 'resource(%d) of type (stream)'),
- array('1', "'1'"),
- array(array(array(1,2,3), array(3,4,5)),
-<<<EOF
-Array &0 (
- 0 => Array &1 (
- 0 => 1
- 1 => 2
- 2 => 3
- )
- 1 => Array &2 (
- 0 => 3
- 1 => 4
- 2 => 5
- )
-)
-EOF
- ),
- // \n\r and \r is converted to \n
- array("this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext",
-<<<EOF
-'this
-is
-a
-very
-very
-very
-very
-very
-very
-long
-text'
-EOF
- ),
- array(new stdClass, 'stdClass Object &%x ()'),
- array($obj,
-<<<EOF
-stdClass Object &%x (
- 'null' => null
- 'boolean' => true
- 'integer' => 1
- 'double' => 1.2
- 'string' => '1'
- 'text' => 'this
-is
-a
-very
-very
-very
-very
-very
-very
-long
-text'
- 'object' => stdClass Object &%x (
- 'foo' => 'bar'
- )
- 'objectagain' => stdClass Object &%x
- 'array' => Array &%d (
- 'foo' => 'bar'
- )
- 'self' => stdClass Object &%x
-)
-EOF
- ),
- array(array(), 'Array &%d ()'),
- array($array,
-<<<EOF
-Array &%d (
- 0 => 0
- 'null' => null
- 'boolean' => true
- 'integer' => 1
- 'double' => 1.2
- 'string' => '1'
- 'text' => 'this
-is
-a
-very
-very
-very
-very
-very
-very
-long
-text'
- 'object' => stdClass Object &%x (
- 'foo' => 'bar'
- )
- 'objectagain' => stdClass Object &%x
- 'array' => Array &%d (
- 'foo' => 'bar'
- )
- 'self' => Array &%d (
- 0 => 0
- 'null' => null
- 'boolean' => true
- 'integer' => 1
- 'double' => 1.2
- 'string' => '1'
- 'text' => 'this
-is
-a
-very
-very
-very
-very
-very
-very
-long
-text'
- 'object' => stdClass Object &%x
- 'objectagain' => stdClass Object &%x
- 'array' => Array &%d (
- 'foo' => 'bar'
- )
- 'self' => Array &%d
- )
-)
-EOF
- ),
- array(
- chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5),
- 'Binary String: 0x000102030405'
- ),
- array(
- implode('', array_map('chr', range(0x0e, 0x1f))),
- 'Binary String: 0x0e0f101112131415161718191a1b1c1d1e1f'
- ),
- array(
- chr(0x00) . chr(0x09),
- 'Binary String: 0x0009'
- ),
- array(
- '',
- "''"
- ),
- );
- }
-
- /**
- * @dataProvider exportProvider
- */
- public function testExport($value, $expected)
- {
- $this->assertStringMatchesFormat($expected, self::trimnl(PHPUnit_Util_Type::export($value)));
- }
-
- public function shortenedExportProvider()
- {
- $obj = new stdClass;
- $obj->foo = 'bar';
-
- $array = array(
- 'foo' => 'bar',
- );
-
- return array(
- array(NULL, 'null'),
- array(TRUE, 'true'),
- array(1, '1'),
- array(1.0, '1.0'),
- array(1.2, '1.2'),
- array('1', "'1'"),
- // \n\r and \r is converted to \n
- array("this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext", "'this\\nis\\na\\nvery\\nvery\\nvery\\nvery...g\\ntext'"),
- array(new stdClass, 'stdClass Object ()'),
- array($obj, 'stdClass Object (...)'),
- array(array(), 'Array ()'),
- array($array, 'Array (...)'),
- );
- }
-
- /**
- * @dataProvider shortenedExportProvider
- */
- public function testShortenedExport($value, $expected)
- {
- $this->assertSame($expected, self::trimnl(PHPUnit_Util_Type::shortenedExport($value)));
- }
-
- public function provideNonBinaryMultibyteStrings()
- {
- return array(
- array(implode('', array_map('chr', range(0x09, 0x0d))), 5),
- array(implode('', array_map('chr', range(0x20, 0x7f))), 96),
- array(implode('', array_map('chr', range(0x80, 0xff))), 128),
- );
- }
-
-
- /**
- * @dataProvider provideNonBinaryMultibyteStrings
- */
- public function testNonBinaryStringExport($value, $expectedLength)
- {
- $this->assertRegExp("~'.{{$expectedLength}}'\$~s", PHPUnit_Util_Type::export($value));
- }
-}
View
1  composer.json
@@ -29,6 +29,7 @@
"phpunit/phpunit-mock-objects": "1.3.*@dev",
"symfony/yaml": ">=2.1.0,<2.2.0",
"sebastian/diff": ">=1.0.0",
+ "sebastian/exporter": ">=1.0.0",
"sebastian/version": ">=1.0.0",
"ext-dom": "*",
"ext-pcre": "*",
View
3  package.xml
@@ -179,9 +179,6 @@
<file baseinstalldir="/" name="NamePrettifier.php" role="php" />
<file baseinstalldir="/" name="ResultPrinter.php" role="php" />
</dir>
- <dir name="Type">
- <file baseinstalldir="/" name="ExportContext.php" role="php" />
- </dir>
<file baseinstalldir="/" name="Configuration.php" role="php" />
<file baseinstalldir="/" name="DeprecatedFeature.php" role="php" />
<file baseinstalldir="/" name="ErrorHandler.php" role="php" />
Please sign in to comment.
Something went wrong with that request. Please try again.