From f287ef358d6f868709c170e39c014ca490a4f74a Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Mon, 26 Nov 2012 15:59:35 +0800 Subject: [PATCH 01/12] Alter PHPUnit_Util_Type::recursiveExport() to handle repeated and recursive data structures more gracefully (and with less memory usage). --- PHPUnit/Autoload.php | 1 + PHPUnit/Util/Type.php | 102 +++++++-------- PHPUnit/Util/Type/ExportContext.php | 189 ++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+), 57 deletions(-) create mode 100644 PHPUnit/Util/Type/ExportContext.php diff --git a/PHPUnit/Autoload.php b/PHPUnit/Autoload.php index 6eb560544b9..495c40adda3 100644 --- a/PHPUnit/Autoload.php +++ b/PHPUnit/Autoload.php @@ -175,6 +175,7 @@ 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' ); diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index 74f5ac72022..9d2a3953d2e 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -105,13 +105,15 @@ public static function export($value, $indentation = 0) * * @param mixed $value The value to export * @param integer $indentation The indentation level of the 2nd+ line - * @param array $processedObjects Contains all objects that were already - * rendered + * @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, &$processedObjects = array()) + protected static function recursiveExport(&$value, $indentation, $processed = null) { if ($value === NULL) { return 'null'; @@ -125,82 +127,68 @@ protected static function recursiveExport($value, $indentation, &$processedObjec return 'false'; } + if (is_float($value) && floatval(intval($value)) === $value) { + return "$value.0"; + } + 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) . - "'"; } - $origValue = $value; - - if (is_object($value)) { - if (in_array($value, $processedObjects, TRUE)) { - return sprintf( - '%s Object (*RECURSION*)', - - get_class($value) - ); - } + $whitespace = str_repeat(' ', 4 * $indentation); - $processedObjects[] = $value; - - // Convert object to array - $value = self::toArray($value); + if (!$processed) { + $processed = new PHPUnit_Util_Type_ExportContext; } if (is_array($value)) { - $whitespace = str_repeat(' ', $indentation); - - // 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($value, 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)(integer)$recursiveKey === $recursiveKey) { - $recursiveKeys[$key] = (integer)$recursiveKey; - } + if (($key = $processed->contains($value)) !== false) { + return "Array &$key"; } - $content = ''; - - foreach ($value as $key => $val) { - if (in_array($key, $recursiveKeys, TRUE)) { - $val = 'Array (*RECURSION*)'; - } + $key = $processed->add($value); + $output = "\n{$whitespace}Array &$key\n$whitespace(\n"; + foreach ($value as $k => $v) { + $output .= "$whitespace [$k] => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; + } + return "$output$whitespace)\n"; + } - else { - $val = self::recursiveExport($val, $indentation+1, $processedObjects); - } + if (is_object($value)) { + $class = get_class($value); - $content .= $whitespace . ' ' . self::export($key) . ' => ' . $val . "\n"; + if ($hash = $processed->contains($value)) { + return "$class Object &$hash"; } - if (strlen($content) > 0) { - $content = "\n" . $content . $whitespace; - } + $refl = new ReflectionObject($value); + + $hash = $processed->add($value); + $output = "\n$whitespace$class Object &$hash\n$whitespace(\n"; + foreach ($refl->getProperties() as $prop) { + $prop->setAccessible(true); + $key = $prop->getName(); + if ($prop->isProtected()) { + $key .= ':protected'; + } elseif ($prop->isPrivate()) { + $key .= ':private'; + } - return sprintf( - "%s (%s)", + $propValue = $prop->getValue($value); + $output .= "$whitespace [$key] => ".self::recursiveExport($propValue, $indentation + 1, $processed)."\n"; - is_object($origValue) ? get_class($origValue) . ' Object' : 'Array', - $content - ); - } + if (!$prop->isPublic()) { + $prop->setAccessible(false); + } + } - if (is_double($value) && (double)(integer)$value === $value) { - return $value . '.0'; + return "$output$whitespace)\n"; } - return (string)$value; + return var_export($value, true); } /** diff --git a/PHPUnit/Util/Type/ExportContext.php b/PHPUnit/Util/Type/ExportContext.php new file mode 100644 index 00000000000..c18d409aa74 --- /dev/null +++ b/PHPUnit/Util/Type/ExportContext.php @@ -0,0 +1,189 @@ +. + * 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 + * @copyright 2001-2012 Sebastian Bergmann + * @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.9.0 + */ + +/** + * A context containing previously rendered arrays and objects when recursively + * exporting a value. + * + * @package PHPUnit + * @subpackage Util + * @author Adam Harvey + * @copyright 2001-2012 Sebastian Bergmann + * @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.9.0 + */ +class PHPUnit_Util_Type_ExportContext { + /** + * Previously seen arrays. + * + * @var array[] $arrays + */ + protected $arrays; + + /** + * Previously seen objects. + * + * @var SplObjectStorage $objects + */ + protected $objects; + + /** Initialises the context. */ + public function __construct() + { + $this->arrays = []; + $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); + } elseif (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); + } elseif (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; + } +} From 044d8b96b49a0bbf87c1d2ceeda2a5616cbd614c Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Mon, 10 Dec 2012 14:24:02 +0800 Subject: [PATCH 02/12] Remove the ReflectionObject stuff and hang off ::toArray(), since it handles undeclared properties correctly. --- PHPUnit/Util/Type.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index 9d2a3953d2e..4d6439769bd 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -164,25 +164,10 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu return "$class Object &$hash"; } - $refl = new ReflectionObject($value); - $hash = $processed->add($value); $output = "\n$whitespace$class Object &$hash\n$whitespace(\n"; - foreach ($refl->getProperties() as $prop) { - $prop->setAccessible(true); - $key = $prop->getName(); - if ($prop->isProtected()) { - $key .= ':protected'; - } elseif ($prop->isPrivate()) { - $key .= ':private'; - } - - $propValue = $prop->getValue($value); - $output .= "$whitespace [$key] => ".self::recursiveExport($propValue, $indentation + 1, $processed)."\n"; - - if (!$prop->isPublic()) { - $prop->setAccessible(false); - } + foreach (self::toArray($value) as $k => $v) { + $output .= "$whitespace [$k] => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; } return "$output$whitespace)\n"; From e490db7d862e0b2fbf69d016d8b6680b2f7c1841 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 15:18:28 +0800 Subject: [PATCH 03/12] Add ExportContext.php to the package.xml. --- package.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.xml b/package.xml index d6f8301ccfc..946f2ce6786 100644 --- a/package.xml +++ b/package.xml @@ -170,6 +170,9 @@ + + + From 571f815743a38dcd653971b4882a5db1e034b98c Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 15:33:23 +0800 Subject: [PATCH 04/12] Change recursiveExport() output to be closer to what was previously there. Specifically, we don't want to move to a newline for the leading line of exported arrays and objects, and we don't want a newline before the opening parenthesis. --- PHPUnit/Util/Type.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index 4d6439769bd..43759b6fecc 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -150,9 +150,9 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu } $key = $processed->add($value); - $output = "\n{$whitespace}Array &$key\n$whitespace(\n"; + $output = "Array &$key (\n"; foreach ($value as $k => $v) { - $output .= "$whitespace [$k] => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; + $output .= "$whitespace '$k' => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; } return "$output$whitespace)\n"; } @@ -165,7 +165,7 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu } $hash = $processed->add($value); - $output = "\n$whitespace$class Object &$hash\n$whitespace(\n"; + $output = "$class Object &$hash (\n"; foreach (self::toArray($value) as $k => $v) { $output .= "$whitespace [$k] => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; } From cd81a9851e40c2ec680ac5e9ec60b28510f9a0cb Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 15:35:12 +0800 Subject: [PATCH 05/12] Reinstate the previous CRLF folding behaviour in recursiveExport(). --- PHPUnit/Util/Type.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index 43759b6fecc..4650bf57837 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -136,6 +136,10 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu 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); From 07efcc252a277b2559c23133e7711e5fdd3dae86 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 15:41:24 +0800 Subject: [PATCH 06/12] Remove more extraneous newlines. --- PHPUnit/Util/Type.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index 4650bf57837..b48676b10e3 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -158,7 +158,7 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu foreach ($value as $k => $v) { $output .= "$whitespace '$k' => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; } - return "$output$whitespace)\n"; + return "$output$whitespace)"; } if (is_object($value)) { @@ -174,7 +174,7 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu $output .= "$whitespace [$k] => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; } - return "$output$whitespace)\n"; + return "$output$whitespace)"; } return var_export($value, true); From 6a5dc0b2b54b774b8df9d5768ad37b15088dff9d Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 15:42:24 +0800 Subject: [PATCH 07/12] Update object properties to be single quoted as well. --- PHPUnit/Util/Type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index b48676b10e3..bb047ba7a68 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -171,7 +171,7 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu $hash = $processed->add($value); $output = "$class Object &$hash (\n"; foreach (self::toArray($value) as $k => $v) { - $output .= "$whitespace [$k] => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; + $output .= "$whitespace '$k' => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; } return "$output$whitespace)"; From 3a49bd167945116365ac9164282f9912bea5b15e Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 15:44:11 +0800 Subject: [PATCH 08/12] Use self::export() for array and property keys as the old code did. --- PHPUnit/Util/Type.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index bb047ba7a68..afb67f6e34f 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -156,7 +156,8 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu $key = $processed->add($value); $output = "Array &$key (\n"; foreach ($value as $k => $v) { - $output .= "$whitespace '$k' => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; + $k = self::export($k); + $output .= "$whitespace $k => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; } return "$output$whitespace)"; } @@ -171,7 +172,8 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu $hash = $processed->add($value); $output = "$class Object &$hash (\n"; foreach (self::toArray($value) as $k => $v) { - $output .= "$whitespace '$k' => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; + $k = self::export($k); + $output .= "$whitespace $k => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; } return "$output$whitespace)"; From 22bf08aa830f0ee6d606c7bd6a77c5baab6d0474 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 15:48:16 +0800 Subject: [PATCH 09/12] Update the recursiveExport() output to better match the old behaviour. --- PHPUnit/Util/Type.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index afb67f6e34f..3b14f2848fa 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -154,12 +154,18 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu } $key = $processed->add($value); - $output = "Array &$key (\n"; - foreach ($value as $k => $v) { - $k = self::export($k); - $output .= "$whitespace $k => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; + if (count($value) > 0) { + $output = "Array &$key (\n"; + + foreach ($value as $k => $v) { + $k = self::export($k); + $output .= "$whitespace $k => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; + } + + return "$output$whitespace)"; + } else { + return "Array &$key ()"; } - return "$output$whitespace)"; } if (is_object($value)) { @@ -170,13 +176,20 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu } $hash = $processed->add($value); - $output = "$class Object &$hash (\n"; - foreach (self::toArray($value) as $k => $v) { - $k = self::export($k); - $output .= "$whitespace $k => ".self::recursiveExport($v, $indentation + 1, $processed)."\n"; + $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 "$output$whitespace)"; } return var_export($value, true); From cd00cca8d2862e2ecd3f9e916b78d09a6f8c1358 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 15:48:43 +0800 Subject: [PATCH 10/12] Update PHPUnit_Util_Type tests to handle the new output format of recursiveExport(). --- Tests/Util/TypeTest.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/Util/TypeTest.php b/Tests/Util/TypeTest.php index 7a7056ef434..26db002ae6e 100644 --- a/Tests/Util/TypeTest.php +++ b/Tests/Util/TypeTest.php @@ -126,10 +126,10 @@ public function exportProvider() text' EOF ), - array(new stdClass, 'stdClass Object ()'), + array(new stdClass, 'stdClass Object &%x ()'), array($obj, << null 'boolean' => true 'integer' => 1 @@ -146,21 +146,21 @@ public function exportProvider() very long text' - 'object' => stdClass Object ( + 'object' => stdClass Object &%x ( 'foo' => 'bar' ) - 'objectagain' => stdClass Object (*RECURSION*) - 'array' => Array ( + 'objectagain' => stdClass Object &%x + 'array' => Array &%d ( 'foo' => 'bar' ) - 'self' => stdClass Object (*RECURSION*) + 'self' => stdClass Object &%x ) EOF ), - array(array(), 'Array ()'), + array(array(), 'Array &%d ()'), array($array, << 0 'null' => null 'boolean' => true @@ -178,14 +178,14 @@ public function exportProvider() very long text' - 'object' => stdClass Object ( + 'object' => stdClass Object &%x ( 'foo' => 'bar' ) - 'objectagain' => stdClass Object (*RECURSION*) - 'array' => Array ( + 'objectagain' => stdClass Object &%x + 'array' => Array &%d ( 'foo' => 'bar' ) - 'self' => Array (*RECURSION*) + 'self' => Array &%d ) EOF ), @@ -213,7 +213,7 @@ public function exportProvider() */ public function testExport($value, $expected) { - $this->assertSame($expected, self::trimnl(PHPUnit_Util_Type::export($value))); + $this->assertStringMatchesFormat($expected, self::trimnl(PHPUnit_Util_Type::export($value))); } public function shortenedExportProvider() From 52ed0758b4682d9078b62a6834e3d4eefadd565b Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 8 Jan 2013 16:02:30 +0800 Subject: [PATCH 11/12] Update constraint tests for the new recursiveExport() output format. --- Tests/Framework/ConstraintTest.php | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Tests/Framework/ConstraintTest.php b/Tests/Framework/ConstraintTest.php index 9d057b6046b..87e3058c88f 100644 --- a/Tests/Framework/ConstraintTest.php +++ b/Tests/Framework/ConstraintTest.php @@ -737,6 +737,8 @@ public function isEqualProvider() $storage1->attach($b); $storage2 = new SplObjectStorage; $storage2->attach($b); + $storage1hash = spl_object_hash($storage1); + $storage2hash = spl_object_hash($storage2); $dom1 = new DOMDocument; $dom1->preserveWhiteSpace = FALSE; @@ -892,17 +894,17 @@ public function isEqualProvider() --- Expected +++ Actual @@ @@ - SplObjectStorage Object ( -- '$ahash' => Array ( -- 'obj' => stdClass Object ( +-SplObjectStorage Object &$storage1hash ( +- '$ahash' => Array &0 ( +- 'obj' => stdClass Object &$ahash ( - 'foo' => 'bar' - ) -- 'inf' => null -- ) - '$bhash' => Array ( - 'obj' => stdClass Object () ++SplObjectStorage Object &$storage2hash ( ++ '$bhash' => Array &0 ( ++ 'obj' => stdClass Object &$bhash () 'inf' => null ) +- '$bhash' => Array &0 ) EOF @@ -1387,8 +1389,8 @@ public function testConstraintIsType() } catch (PHPUnit_Framework_ExpectationFailedException $e) { - $this->assertEquals(<<assertStringMatchesFormat(<<assertEquals(<<assertStringMatchesFormat(<<assertEquals("contains stdClass Object ()", $constraint->toString()); + $this->assertStringMatchesFormat("contains stdClass Object &%s ()", $constraint->toString()); $storage = new SplObjectStorage; $this->assertFalse($constraint->evaluate($storage, '', TRUE)); @@ -3206,9 +3208,9 @@ public function testConstraintSplObjectStorageContains() } catch (PHPUnit_Framework_ExpectationFailedException $e) { - $this->assertEquals( + $this->assertStringMatchesFormat( <<assertEquals( + $this->assertStringMatchesFormat( << Date: Tue, 8 Jan 2013 16:03:42 +0800 Subject: [PATCH 12/12] Fix dates and version numbers. --- PHPUnit/Util/Type/ExportContext.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PHPUnit/Util/Type/ExportContext.php b/PHPUnit/Util/Type/ExportContext.php index c18d409aa74..9a2b3f64082 100644 --- a/PHPUnit/Util/Type/ExportContext.php +++ b/PHPUnit/Util/Type/ExportContext.php @@ -2,7 +2,7 @@ /** * PHPUnit * - * Copyright (c) 2001-2012, Sebastian Bergmann . + * Copyright (c) 2001-2013, Sebastian Bergmann . * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,10 +37,10 @@ * @package PHPUnit * @subpackage Util * @author Adam Harvey - * @copyright 2001-2012 Sebastian Bergmann + * @copyright 2001-2013 Sebastian Bergmann * @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.9.0 + * @since File available since Release 3.8.0 */ /** @@ -50,10 +50,10 @@ * @package PHPUnit * @subpackage Util * @author Adam Harvey - * @copyright 2001-2012 Sebastian Bergmann + * @copyright 2001-2013 Sebastian Bergmann * @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.9.0 + * @since Class available since Release 3.8.0 */ class PHPUnit_Util_Type_ExportContext { /**