123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\VarDumper\Tests;
- use Symfony\Component\VarDumper\Cloner\VarCloner;
- /**
- * @author Nicolas Grekas <p@tchwork.com>
- */
- class VarClonerTest extends \PHPUnit_Framework_TestCase
- {
- public function testMaxIntBoundary()
- {
- $data = array(PHP_INT_MAX => 123);
- $cloner = new VarCloner();
- $clone = $cloner->cloneVar($data);
- $expected = <<<EOTXT
- Symfony\Component\VarDumper\Cloner\Data Object
- (
- [data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
- (
- [0] => Array
- (
- [0] => Symfony\Component\VarDumper\Cloner\Stub Object
- (
- [type] => array
- [class] => assoc
- [value] => 1
- [cut] => 0
- [handle] => 0
- [refCount] => 0
- [position] => 1
- )
- )
- [1] => Array
- (
- [%s] => 123
- )
- )
- [maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
- [maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
- [useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
- )
- EOTXT;
- $this->assertSame(sprintf($expected, PHP_INT_MAX), print_r($clone, true));
- }
- public function testClone()
- {
- $json = json_decode('{"1":{"var":"val"},"2":{"var":"val"}}');
- $cloner = new VarCloner();
- $clone = $cloner->cloneVar($json);
- $expected = <<<EOTXT
- Symfony\Component\VarDumper\Cloner\Data Object
- (
- [data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
- (
- [0] => Array
- (
- [0] => Symfony\Component\VarDumper\Cloner\Stub Object
- (
- [type] => object
- [class] => stdClass
- [value] =>
- [cut] => 0
- [handle] => %i
- [refCount] => 0
- [position] => 1
- )
- )
- [1] => Array
- (
- [\000+\0001] => Symfony\Component\VarDumper\Cloner\Stub Object
- (
- [type] => object
- [class] => stdClass
- [value] =>
- [cut] => 0
- [handle] => %i
- [refCount] => 0
- [position] => 2
- )
- [\000+\0002] => Symfony\Component\VarDumper\Cloner\Stub Object
- (
- [type] => object
- [class] => stdClass
- [value] =>
- [cut] => 0
- [handle] => %i
- [refCount] => 0
- [position] => 3
- )
- )
- [2] => Array
- (
- [\000+\000var] => val
- )
- [3] => Array
- (
- [\000+\000var] => val
- )
- )
- [maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
- [maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
- [useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
- )
- EOTXT;
- $this->assertStringMatchesFormat($expected, print_r($clone, true));
- }
- public function testCaster()
- {
- $cloner = new VarCloner(array(
- '*' => function ($obj, $array) {
- return array('foo' => 123);
- },
- __CLASS__ => function ($obj, $array) {
- ++$array['foo'];
- return $array;
- },
- ));
- $clone = $cloner->cloneVar($this);
- $expected = <<<EOTXT
- Symfony\Component\VarDumper\Cloner\Data Object
- (
- [data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
- (
- [0] => Array
- (
- [0] => Symfony\Component\VarDumper\Cloner\Stub Object
- (
- [type] => object
- [class] => %s
- [value] =>
- [cut] => 0
- [handle] => %i
- [refCount] => 0
- [position] => 1
- )
- )
- [1] => Array
- (
- [foo] => 124
- )
- )
- [maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
- [maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
- [useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
- )
- EOTXT;
- $this->assertStringMatchesFormat($expected, print_r($clone, true));
- }
- }
|