Вход Регистрация
Файл: gapps/vendor/symfony/var-dumper/Tests/VarClonerTest.php
Строк: 229
<?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 SymfonyComponentVarDumperTests;

use 
SymfonyComponentVarDumperClonerVarCloner;

/**
 * @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
SymfonyComponentVarDumperClonerData Object
(
    [data:SymfonyComponentVarDumperClonerData:private] => Array
        (
            [0] => Array
                (
                    [0] => SymfonyComponentVarDumperClonerStub Object
                        (
                            [type] => array
                            [class] => assoc
                            [value] => 1
                            [cut] => 0
                            [handle] => 0
                            [refCount] => 0
                            [position] => 1
                        )

                )

            [1] => Array
                (
                    [%s] => 123
                )

        )

    [maxDepth:SymfonyComponentVarDumperClonerData:private] => 20
    [maxItemsPerDepth:SymfonyComponentVarDumperClonerData:private] => -1
    [useRefHandles:SymfonyComponentVarDumperClonerData:private] => -1
)

EOTXT;
        
$this->assertSame(sprintf($expectedPHP_INT_MAX), print_r($clonetrue));
    }

    public function 
testClone()
    {
        
$json json_decode('{"1":{"var":"val"},"2":{"var":"val"}}');

        
$cloner = new VarCloner();
        
$clone $cloner->cloneVar($json);

        
$expected = <<<EOTXT
SymfonyComponentVarDumperClonerData Object
(
    [data:SymfonyComponentVarDumperClonerData:private] => Array
        (
            [0] => Array
                (
                    [0] => SymfonyComponentVarDumperClonerStub Object
                        (
                            [type] => object
                            [class] => stdClass
                            [value] => 
                            [cut] => 0
                            [handle] => %i
                            [refCount] => 0
                            [position] => 1
                        )

                )

            [1] => Array
                (
                    [00+001] => SymfonyComponentVarDumperClonerStub Object
                        (
                            [type] => object
                            [class] => stdClass
                            [value] => 
                            [cut] => 0
                            [handle] => %i
                            [refCount] => 0
                            [position] => 2
                        )

                    [00+002] => SymfonyComponentVarDumperClonerStub Object
                        (
                            [type] => object
                            [class] => stdClass
                            [value] => 
                            [cut] => 0
                            [handle] => %i
                            [refCount] => 0
                            [position] => 3
                        )

                )

            [2] => Array
                (
                    [00+00var] => val
                )

            [3] => Array
                (
                    [00+00var] => val
                )

        )

    [maxDepth:SymfonyComponentVarDumperClonerData:private] => 20
    [maxItemsPerDepth:SymfonyComponentVarDumperClonerData:private] => -1
    [useRefHandles:SymfonyComponentVarDumperClonerData:private] => -1
)

EOTXT;
        
$this->assertStringMatchesFormat($expectedprint_r($clonetrue));
    }

    public function 
testJsonCast()
    {
        
$data = (array) json_decode('{"1":{}}');

        
$cloner = new VarCloner();
        
$clone $cloner->cloneVar($data);

        
$expected = <<<'EOTXT'
object(SymfonyComponentVarDumperClonerData)#%i (4) {
  ["data":"SymfonyComponentVarDumperClonerData":private]=>
  array(2) {
    [0]=>
    array(1) {
      [0]=>
      object(SymfonyComponentVarDumperClonerStub)#%i (7) {
        ["type"]=>
        string(5) "array"
        ["class"]=>
        string(5) "assoc"
        ["value"]=>
        int(1)
        ["cut"]=>
        int(0)
        ["handle"]=>
        int(0)
        ["refCount"]=>
        int(0)
        ["position"]=>
        int(1)
      }
    }
    [1]=>
    array(1) {
      ["1"]=>
      object(SymfonyComponentVarDumperClonerStub)#%i (7) {
        ["type"]=>
        string(6) "object"
        ["class"]=>
        string(8) "stdClass"
        ["value"]=>
        NULL
        ["cut"]=>
        int(0)
        ["handle"]=>
        int(%i)
        ["refCount"]=>
        int(0)
        ["position"]=>
        int(0)
      }
    }
  }
  ["maxDepth":"SymfonyComponentVarDumperClonerData":private]=>
  int(20)
  ["maxItemsPerDepth":"SymfonyComponentVarDumperClonerData":private]=>
  int(-1)
  ["useRefHandles":"SymfonyComponentVarDumperClonerData":private]=>
  int(-1)
}

EOTXT;
        
ob_start();
        
var_dump($clone);
        
$this->assertStringMatchesFormat($expectedob_get_clean());
    }

    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
SymfonyComponentVarDumperClonerData Object
(
    [data:SymfonyComponentVarDumperClonerData:private] => Array
        (
            [0] => Array
                (
                    [0] => SymfonyComponentVarDumperClonerStub Object
                        (
                            [type] => object
                            [class] => %s
                            [value] => 
                            [cut] => 0
                            [handle] => %i
                            [refCount] => 0
                            [position] => 1
                        )

                )

            [1] => Array
                (
                    [foo] => 124
                )

        )

    [maxDepth:SymfonyComponentVarDumperClonerData:private] => 20
    [maxItemsPerDepth:SymfonyComponentVarDumperClonerData:private] => -1
    [useRefHandles:SymfonyComponentVarDumperClonerData:private] => -1
)

EOTXT;
        
$this->assertStringMatchesFormat($expectedprint_r($clonetrue));
    }
}
Онлайн: 0
Реклама