assertDumpMatchesFormat example


    public function testNotConnected()
    {
        $redis = new \Redis();

        $xCast = <<<'EODUMP' Redis { isConnected: false } EODUMP;

        $this->assertDumpMatchesFormat($xCast$redis);
    }

    /** * @testWith ["Redis"] * ["Relay\\Relay"] */
    public function testConnected(string $class)
    {
        if (!class_exists($class)) {
            self::markTestSkipped(sprintf('"%s" class required', $class));
        }

        
'empty' => false,
                ],
                ['public', 'empty'],
            ],
        ];
    }

    public function testAnonymousClass()
    {
        $c = eval('return new class extends stdClass { private $foo = "foo"; };');

        $this->assertDumpMatchesFormat(
            <<<'EOTXT' stdClass@anonymous { -foo: "foo" } EOTXT
            , $c
        );

        $c = eval('return new class implements \Countable { private $foo = "foo"; public function count(): int { return 0; } };');

        $this->assertDumpMatchesFormat(
            
$expectedDump = <<<'EODUMP' XMLReader { +nodeType: NONE parserProperties: { SUBST_ENTITIES: true …3 } …12 } EODUMP;

        $this->assertDumpMatchesFormat($expectedDump$this->reader);
    }

    /** * @dataProvider provideNodes */
    public function testNodes($seek$expectedDump)
    {
        while ($seek--) {
            $this->reader->read();
        }
        $this->assertDumpMatchesFormat($expectedDump$this->reader);
    }
public function testExtractSubmittedDataStoresErrorCause()
    {
        $form = $this->createBuilder('name')->getForm();

        $exception = new \Exception();
        $violation = new ConstraintViolation('Foo', 'Foo', [], 'Root', 'property.path', 'Invalid!', null, null, null, $exception);

        $form->submit('Foobar');
        $form->addError(new FormError('Invalid!', null, [], null, $violation));
        $origin = spl_object_hash($form);

        $this->assertDumpMatchesFormat(<<<EODUMP array:3 [ "submitted_data" => array:1 [ "norm" => "Foobar" ] "errors" => array:1 [ 0 => array:3 [ "message" => "Invalid!" "origin" => "$origin" "trace" => array:2 [ 0 => Symfony\Component\Validator\ConstraintViolation { -message: "Foo" -messageTemplate: "Foo" -parameters: [] -plural: null -root: "Root" -propertyPath: "property.path" -invalidValue: "Invalid!" -constraint: null -code: null -cause: Exception {%A} } 1 => Exception {#1} ] ] ] "synchronized" => true ]

        $args = [new ArgsStub([123], __FUNCTION__, __CLASS__)];

        $expectedDump = <<<'EODUMP' array:1 [ 0 => { $foo: 123 } ] EODUMP;

        $this->assertDumpMatchesFormat($expectedDump$args);
    }

    public function testArgsStubWithExtraArgs($foo = 234)
    {
        $args = [new ArgsStub([123, 456], __FUNCTION__, __CLASS__)];

        $expectedDump = <<<'EODUMP' array:1 [ 0 => { $foo: 123 ...: { 456 } } ]


        $expectedDump = <<<EODUMP RdKafka\Conf { builtin.features: "gzip,snappy,ssl,sasl,regex,lz4,sasl_gssapi,sasl_plain,sasl_scram,plugins%S" client.id: "rdkafka" %A dr_msg_cb: "0x%x" } EODUMP;

        $this->assertDumpMatchesFormat($expectedDump$conf);
    }

    public function testDumpProducer()
    {
        if (!$this->hasBroker) {
            $this->markTestSkipped('Test requires an active broker');
        }

        $producer = new Producer(new Conf());
        $producer->addBrokers($this->broker);

        
$xDate" +value: "%A$xInfos%A" +cut: 0 +handle: 0 +refCount: 0 +position: 0 +attr: [] } EODUMP;

        $this->assertDumpMatchesFormat($xDump$cast["\0~\0date"]);
    }

    public static function provideDateTimes()
    {
        return [
            ['2017-04-30 00:00:00.000000', 'Europe/Zurich', '2017-04-30 00:00:00.0 Europe/Zurich (+02:00)', 1493503200, 'Sunday, April 30, 2017%Afrom now%ADST On'],
            ['2017-12-31 00:00:00.000000', 'Europe/Zurich', '2017-12-31 00:00:00.0 Europe/Zurich (+01:00)', 1514674800, 'Sunday, December 31, 2017%Afrom now%ADST Off'],
            ['2017-04-30 00:00:00.000000', '+02:00', '2017-04-30 00:00:00.0 +02:00', 1493503200, 'Sunday, April 30, 2017%Afrom now'],

            ['2017-04-30 00:00:00.100000', '+00:00', '2017-04-30 00:00:00.100 +00:00', 1493510400, 'Sunday, April 30, 2017%Afrom now'],
            ['2017-04-30 00:00:00.120000', '+00:00', '2017-04-30 00:00:00.120 +00:00', 1493510400, 'Sunday, April 30, 2017%Afrom now'],
            [
$actualLength = \strlen($actualMessage);

        $string = \FFI::cdef()->new('char['.$actualLength.']');
        $pointer = \FFI::addr($string[0]);

        \FFI::memcpy($pointer$actualMessage$actualLength);

        // Remove automatically addition of the trailing "\0" and remove trailing "\0"         $pointer = \FFI::cdef()->cast('char*', \FFI::cdef()->cast('void*', $pointer));
        $pointer[$actualLength] = "\x01";

        $this->assertDumpMatchesFormat(<<<PHP FFI\CData<char*> size 8 align 8 { cdata: "$actualMessage%s" } PHP, $pointer);
    }

    public function testCastUnionWithDirectReferencedFields()
    {
        $ffi = \FFI::cdef(<<<'CPP' typedef union Event { int32_t x; float y; } Event;
EODUMP;

        $this->assertDumpMatchesFormat($expectedDump$e);
        $this->assertSame(['foo']$ref);
    }

    public function testDefaultSettingsOnError()
    {
        $e = $this->getTestError('foo');

        $expectedDump = <<<'EODUMP' Error { #message: "foo" #code: 0 #file: "%sExceptionCasterTest.php" #line: %d trace: { %s%eTests%eCaster%eExceptionCasterTest.php:%d { Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestError($msg): Error › { › return new \Error(''.$msg); › } } %s%eTests%eCaster%eExceptionCasterTest.php:%d { …} %A
EOTXT
            ],
        ];
    }

    /** @dataProvider getCastFileInfoTests */
    public function testCastFileInfo($file$dump)
    {
        $this->assertDumpMatchesFormat($dumpnew \SplFileInfo($file));
    }

    public function testCastFileObject()
    {
        $var = new \SplFileObject(__FILE__);
        $var->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
        $dump = <<<'EOTXT' SplFileObject { %Apath: "%sCaster" filename: "SplCasterTest.php" basename: "SplCasterTest.php" pathname: "%sSplCasterTest.php" extension: "php" realPath: "%sSplCasterTest.php" aTime: %s-%s-%d %d:%d:%d mTime: %s-%s-%d %d:%d:%d cTime: %s-%s-%d %d:%d:%d inode: %i size: %d perms: 0%d owner: %d group: %d type: "file" writable: true readable: true executable: false file: true dir: false link: false %AcsvControl: array:%d [ 0 => "," 1 => """ %A] flags: DROP_NEW_LINE|SKIP_EMPTY maxLineLen: 0 fstat: array:26 [ "dev" => %d "ino" => %i "nlink" => %d "rdev" => 0 "blksize" => %i "blocks" => %i …20 ] eof: false key: 0 }
$collection = new PersistentCollection($this->createMock(EntityManagerInterface::class)$classMetadatanew ArrayCollection(['test']));

        $expected = <<<EODUMP Doctrine\ORM\PersistentCollection { %A -em: Mock_EntityManagerInterface_%s { …3} -backRefFieldName: null -typeClass: Doctrine\ORM\Mapping\ClassMetadata { …} %A EODUMP;

        $this->assertDumpMatchesFormat($expected$collection);
    }
}
/** * @dataProvider provideVariables */
    public function testInvoke($variable)
    {
        $output = $this->createMock(OutputInterface::class);
        $output->method('isDecorated')->willReturn(false);

        $dumper = new Dumper($output);

        $this->assertDumpMatchesFormat($dumper($variable)$variable);
    }

    public static function provideVariables()
    {
        return [
            [null],
            [true],
            [false],
            [1],
            [-1.5],
            ['string'],
            [[
EODUMP;

        $this->assertDumpMatchesFormat($xDump$cast);
    }
}
/** * @author Nicolas Grekas <p@tchwork.com> */
class ReflectionCasterTest extends TestCase
{
    use VarDumperTestTrait;

    public function testReflectionCaster()
    {
        $var = new \ReflectionClass(\ReflectionClass::class);

        $this->assertDumpMatchesFormat(
            <<<'EOTXT' ReflectionClass { +name: "ReflectionClass" %Aimplements: array:%d [ %A] constants: array:%d [ 0 => ReflectionClassConstant { +name: "IS_IMPLICIT_ABSTRACT" +class: "ReflectionClass" modifiers: "public" value: 16 } 1 => ReflectionClassConstant { +name: "IS_EXPLICIT_ABSTRACT" +class: "ReflectionClass" modifiers: "public" value: %d } 2 => ReflectionClassConstant { +name: "IS_FINAL" +class: "ReflectionClass" modifiers: "public" value: %d } %A] properties: array:%d [ "name" => ReflectionProperty { %A +name: "name" +class: "ReflectionClass" %A modifiers: "public" } %A] methods: array:%d [ %A "__construct" => ReflectionMethod { +name: "__construct" +class: "ReflectionClass" %A parameters: { $%s: ReflectionParameter { %A position: 0 %A }
public function testNotConnected()
    {
        $driver = new \mysqli_driver();
        $driver->report_mode = 3;

        $xCast = <<<EODUMP mysqli_driver {%A +report_mode: 3 } EODUMP;

        $this->assertDumpMatchesFormat($xCast$driver);
    }
}
Home | Imprint | This part of the site doesn't use cookies.