assertDumpEquals example

EOTXT;
        $this->assertDumpEquals($expected$var);
    }

    public function testCastMemcachedWithCustomOptions()
    {
        if (!class_exists(\Memcached::class)) {
            $this->markTestSkipped('Memcached not available');
        }

        $var = new \Memcached();
        $var->addServer('127.0.0.1', 11211);
        $var->addServer('127.0.0.2', 11212);

        
$expected .= <<<EODUMP $i => array:4 [ 0 => "a" 1 => "b" 2 => "c" 3 => "d" ]\n EODUMP;
        }
        $expected .= "]\n";

        $this->assertDumpEquals($expected$data);
    }

    public function testAllowsNonScalarExpectation()
    {
        $this->assertDumpEquals(new \ArrayObject(['bim' => 'bam'])new \ArrayObject(['bim' => 'bam']));
    }

    public function testItCanBeConfigured()
    {
        $this->setUpVarDumper($casters = [
            \DateTimeInterface::class => static function D\DateTimeInterface $date, array $a, Stub $stub): array {
                

    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);
    }
}
EOTXT
            , $var
        );
    }

    public function testClosureCasterExcludingVerbosity()
    {
        $var = function D($a = 5) {};

        $this->assertDumpEquals('Closure&($a = 5) { …5}', $var, Caster::EXCLUDE_VERBOSE);
    }

    public function testReflectionParameter()
    {
        $var = new \ReflectionParameter(reflectionParameterFixture::class, 0);

        $this->assertDumpMatchesFormat(
            <<<'EOTXT' ReflectionParameter { +name: "arg1" position: 0 allowsNull: true typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass" }
$expected = <<<EOTXT ArrayObject@anonymous { +"foo": 234 storage: array:1 [ 0 => 123 ] flag::STD_PROP_LIST: false flag::ARRAY_AS_PROPS: false iteratorClass: "ArrayIterator" } EOTXT;
        $this->assertDumpEquals($expected$var);
    }

    public function testArrayIterator()
    {
        $var = new MyArrayIterator([234]);

        $expected = <<<EOTXT Symfony\Component\VarDumper\Tests\Caster\MyArrayIterator { -foo: 123 storage: array:1 [ 0 => 234 ] flag::STD_PROP_LIST: false flag::ARRAY_AS_PROPS: false }
/** * @dataProvider provideFailingSerialization */
    public function testFailingSerialization($value)
    {
        $this->expectException(NotInstantiableTypeException::class);
        $this->expectExceptionMessageMatches('/Type ".*" is not instantiable\./');
        $expectedDump = $this->getDump($value);
        try {
            VarExporter::export($value);
        } finally {
            $this->assertDumpEquals(rtrim($expectedDump)$value);
        }
    }

    public static function provideFailingSerialization()
    {
        yield [hash_init('md5')];
        yield [new \ReflectionClass(\stdClass::class)];
        yield [(new \ReflectionFunction(function D): int {}))->getReturnType()];
        yield [new \ReflectionGenerator((function D) { yield 123; })())];
        yield [function D) {}];
        yield [function D) { yield 123; }];
        
public function testCastFiberNotStarted()
    {
        $fiber = new \Fiber(static fn () => true);

        $expected = <<<EODUMP Fiber { status: "not started" } EODUMP;

        $this->assertDumpEquals($expected$fiber);
    }

    public function testCastFiberTerminated()
    {
        $fiber = new \Fiber(static fn () => true);
        $fiber->start();

        $expected = <<<EODUMP Fiber { status: "terminated" }

    public function testDumpDateTime($time$timezone$xDate$xTimestamp)
    {
        $date = new \DateTime($timenew \DateTimeZone($timezone));

        $xDump = <<<EODUMP DateTime @$xTimestamp { date: $xDate } EODUMP;

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

    /** * @dataProvider provideDateTimes */
    public function testDumpDateTimeImmutable($time$timezone$xDate$xTimestamp)
    {
        $date = new \DateTimeImmutable($timenew \DateTimeZone($timezone));

        $xDump = <<<EODUMP DateTimeImmutable @$xTimestamp { date:
public function testMessageFormatter()
    {
        $var = new \MessageFormatter('en', 'Hello {name}');

        $expected = <<<EOTXT MessageFormatter { locale: "en" pattern: "Hello {name}" } EOTXT;
        $this->assertDumpEquals($expected$var);
    }

    public function testCastNumberFormatter()
    {
        $var = new \NumberFormatter('en', \NumberFormatter::DECIMAL);

        $expectedLocale = $var->getLocale();
        $expectedPattern = $var->getPattern();

        $expectedAttribute1 = $var->getAttribute(\NumberFormatter::PARSE_INT_ONLY);
        $expectedAttribute2 = $var->getAttribute(\NumberFormatter::GROUPING_USED);
        
public function testCastUuid()
    {
        $uuid = new UuidV4('83a9db35-3c8c-4040-b3c1-02eccc00b419');
        $expectedDump = <<<EODUMP Symfony\Component\Uid\UuidV4 { #uid: "83a9db35-3c8c-4040-b3c1-02eccc00b419" toBase58: "HFzAAuYvev42cCjwqpnKqz" toBase32: "43N7DKAF4C810B7G82XK601D0S" } EODUMP;
        $this->assertDumpEquals($expectedDump$uuid);

        $uuid = new UuidV6('1ebc50e9-8a23-6704-ad6f-59afd5cda7e5');
        if (method_exists($uuid, 'getDateTime')) {
            $expectedDump = <<<EODUMP Symfony\Component\Uid\UuidV6 { #uid: "1ebc50e9-8a23-6704-ad6f-59afd5cda7e5" toBase58: "4o8c5m6v4L8h5teww36JDa" toBase32: "0YQH8EK2H3CW2ATVTSNZAWV9Z5" time: "2021-06-04 08:26:44.591386 UTC" } EODUMP;
        }

        if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && 'preload' === \ini_get('ffi.enable')) {
            return;
        }
        if (!filter_var(\ini_get('ffi.enable'), \FILTER_VALIDATE_BOOL)) {
            $this->markTestSkipped('FFI not enabled for CLI SAPI');
        }
    }

    public function testCastAnonymousStruct()
    {
        $this->assertDumpEquals(<<<'PHP' FFI\CData<struct <anonymous>> size 4 align 4 { uint32_t x: 0 } PHP, \FFI::cdef()->new('struct { uint32_t x; }'));
    }

    public function testCastNamedStruct()
    {
        $this->assertDumpEquals(<<<'PHP' FFI\CData<struct Example> size 4 align 4 { uint32_t x: 0 }
public function testFlags()
    {
        putenv('DUMP_LIGHT_ARRAY=1');
        putenv('DUMP_STRING_LENGTH=1');

        $var = [
            range(1, 3),
            ['foo', 2 => 'bar'],
        ];

        $this->assertDumpEquals(
            <<<EOTXT [ [ 1 2 3 ] [ 0 => (3) "foo" 2 => (3) "bar" ] ]
self::assertSame(['foo' => 'bar']$context->getContext());
        self::assertEmpty($context->getNormalizationContext());
        self::assertEmpty($context->getDenormalizationContext());
        self::assertEmpty($context->getGroups());
    }

    /** * @dataProvider provideValidInputs */
    public function testValidInputs(callable $factory, string $expectedDump)
    {
        $this->assertDumpEquals($expectedDump$factory());
    }

    public static function provideValidInputs(): iterable
    {
        yield 'named arguments: with context option' => [
            fn () => new Context(context: ['foo' => 'bar']),
            <<<DUMP Symfony\Component\Serializer\Annotation\Context { -groups: [] -context: [ "foo" => "bar", ] -normalizationContext: [] -denormalizationContext: [] }
Home | Imprint | This part of the site doesn't use cookies.