Stub example

$dumper->dump($cloner->cloneVar($value));

        $this->assertSame($expectedOut$out);
    }

    public function testCollapse()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            $this->markTestSkipped('This test cannot be run on Windows.');
        }

        $stub = new Stub();
        $stub->type = Stub::TYPE_OBJECT;
        $stub->class = 'stdClass';
        $stub->position = 1;

        $data = new Data([
            [
                $stub,
            ],
            [
                "\0~collapse=1\0foo" => 123,
                "\0+\0bar" => [1 => 2],
            ],
use VarDumperTestTrait;

    /** * @requires extension pdo_sqlite */
    public function testCastPdo()
    {
        $pdo = new \PDO('sqlite::memory:');
        $pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, ['PDOStatement', [$pdo]]);
        $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        $cast = PdoCaster::castPdo($pdo[]new Stub(), false);

        $this->assertInstanceOf(EnumStub::class$cast["\0~\0attributes"]);

        $attr = $cast["\0~\0attributes"] = $cast["\0~\0attributes"]->value;
        $this->assertInstanceOf(ConstStub::class$attr['CASE']);
        $this->assertSame('NATURAL', $attr['CASE']->class);
        $this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class);

        $xDump = <<<'EODUMP' array:2 [ "\x00~\x00inTransaction" => false "\x00~\x00attributes" => array:9 [ "CASE" => NATURAL "ERRMODE" => EXCEPTION "PERSISTENT" => false "DRIVER_NAME" => "sqlite" "ORACLE_NULLS" => NATURAL "CLIENT_VERSION" => "%s" "SERVER_VERSION" => "%s" "STATEMENT_CLASS" => array:%d [ 0 => "PDOStatement"%A ] "DEFAULT_FETCH_MODE" => BOTH ] ]


        return $hashCut;
    }

    private function getStub(mixed $item): mixed
    {
        if (!$item || !\is_array($item)) {
            return $item;
        }

        $stub = new Stub();
        $stub->type = Stub::TYPE_ARRAY;
        foreach ($item as $stub->class => $stub->position) {
        }
        if (isset($item[0])) {
            $stub->cut = $item[0];
        }
        $stub->value = $stub->cut + ($stub->position ? \count($this->data[$stub->position]) : 0);

        return $stub;
    }
}
$r = new \ReflectionMethod($r[0]$r[1]);
                } catch (\ReflectionException) {
                    $r = new \ReflectionClass($r[0]);
                }
            }

            if (str_contains($identifier, "@anonymous\0")) {
                $this->value = $identifier = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0]$identifier);
            }

            if (null !== $callable && $r instanceof \ReflectionFunctionAbstract) {
                $s = ReflectionCaster::castFunctionAbstract($r[]new Stub(), true, Caster::EXCLUDE_VERBOSE);
                $s = ReflectionCaster::getSignature($s);

                if (str_ends_with($identifier, '()')) {
                    $this->value = substr_replace($identifier$s, -2);
                } else {
                    $this->value .= $s;
                }
            }
        } catch (\ReflectionException) {
            return;
        } finally {
            
EODUMP;

        $this->assertDumpEquals($xDump$date);
    }

    /** * @dataProvider provideDateTimes */
    public function testCastDateTime($time$timezone$xDate$xTimestamp$xInfos)
    {
        $stub = new Stub();
        $date = new \DateTimeImmutable($timenew \DateTimeZone($timezone));
        $cast = DateCaster::castDateTime($date, Caster::castObject($date, \DateTimeImmutable::class)$stub, false, 0);

        $xDump = <<<EODUMP array:1 [ "\\x00~\\x00date" => $xDate ] EODUMP;

        $this->assertDumpEquals($xDump$cast);

        
        $maxItems = $this->maxItems;
        $maxString = $this->maxString;
        $minDepth = $this->minDepth;
        $currentDepth = 0;              // Current tree depth         $currentDepthFinalIndex = 0;    // Final $queue index for current tree depth         $minimumDepthReached = 0 === $minDepth; // Becomes true when minimum tree depth has been reached         $cookie = (object) [];          // Unique object used to detect hard references         $a = null;                      // Array cast for nested structures         $stub = null;                   // Stub capturing the main properties of an original item value                                         // or null if the original value is used directly
        $arrayStub = new Stub();
        $arrayStub->type = Stub::TYPE_ARRAY;
        $fromObjCast = false;

        for ($i = 0; $i < $len; ++$i) {
            // Detect when we move on to the next tree depth             if ($i > $currentDepthFinalIndex) {
                ++$currentDepth;
                $currentDepthFinalIndex = $len - 1;
                if ($currentDepth >= $minDepth) {
                    $minimumDepthReached = true;
                }
            }

    public function testCastGmp()
    {
        $gmpString = gmp_init('1234');
        $gmpOctal = gmp_init(010);
        $gmp = gmp_init('01101');
        $gmpDump = <<<EODUMP array:1 [ "\\x00~\\x00value" => %s ] EODUMP;
        $this->assertDumpEquals(sprintf($gmpDump$gmpString), GmpCaster::castGmp($gmpString[]new Stub(), false, 0));
        $this->assertDumpEquals(sprintf($gmpDump$gmpOctal), GmpCaster::castGmp($gmpOctal[]new Stub(), false, 0));
        $this->assertDumpEquals(sprintf($gmpDump$gmp), GmpCaster::castGmp($gmp[]new Stub(), false, 0));

        $dump = <<<EODUMP GMP { value: 577 } EODUMP;

        $this->assertDumpEquals($dump$gmp);
    }
}


        return $hashCut;
    }

    private function getStub(mixed $item): mixed
    {
        if (!$item || !\is_array($item)) {
            return $item;
        }

        $stub = new Stub();
        $stub->type = Stub::TYPE_ARRAY;
        foreach ($item as $stub->class => $stub->position) {
        }
        if (isset($item[0])) {
            $stub->cut = $item[0];
        }
        $stub->value = $stub->cut + ($stub->position ? \count($this->data[$stub->position]) : 0);

        return $stub;
    }
}
$r = new \ReflectionMethod($r[0]$r[1]);
                } catch (\ReflectionException) {
                    $r = new \ReflectionClass($r[0]);
                }
            }

            if (str_contains($identifier, "@anonymous\0")) {
                $this->value = $identifier = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0]$identifier);
            }

            if (null !== $callable && $r instanceof \ReflectionFunctionAbstract) {
                $s = ReflectionCaster::castFunctionAbstract($r[]new Stub(), true, Caster::EXCLUDE_VERBOSE);
                $s = ReflectionCaster::getSignature($s);

                if (str_ends_with($identifier, '()')) {
                    $this->value = substr_replace($identifier$s, -2);
                } else {
                    $this->value .= $s;
                }
            }
        } catch (\ReflectionException) {
            return;
        } finally {
            
        $maxItems = $this->maxItems;
        $maxString = $this->maxString;
        $minDepth = $this->minDepth;
        $currentDepth = 0;              // Current tree depth         $currentDepthFinalIndex = 0;    // Final $queue index for current tree depth         $minimumDepthReached = 0 === $minDepth; // Becomes true when minimum tree depth has been reached         $cookie = (object) [];          // Unique object used to detect hard references         $a = null;                      // Array cast for nested structures         $stub = null;                   // Stub capturing the main properties of an original item value                                         // or null if the original value is used directly
        $arrayStub = new Stub();
        $arrayStub->type = Stub::TYPE_ARRAY;
        $fromObjCast = false;

        for ($i = 0; $i < $len; ++$i) {
            // Detect when we move on to the next tree depth             if ($i > $currentDepthFinalIndex) {
                ++$currentDepth;
                $currentDepthFinalIndex = $len - 1;
                if ($currentDepth >= $minDepth) {
                    $minimumDepthReached = true;
                }
            }
Home | Imprint | This part of the site doesn't use cookies.