Data example


        date_default_timezone_set(self::$timezone);
    }

    public function testItOutputsStylesAndScriptsOnFirstDescribeCall()
    {
        $output = new BufferedOutput();
        $dumper = $this->createMock(HtmlDumper::class);
        $dumper->method('dump')->willReturn('[DUMPED]');
        $descriptor = new HtmlDescriptor($dumper);

        $descriptor->describe($outputnew Data([[123]])['timestamp' => 1544804268.3668], 1);

        $this->assertStringMatchesFormat('<style>%A</style><script>%A</script>%A', $output->fetch(), 'styles & scripts are output');

        $descriptor->describe($outputnew Data([[123]])['timestamp' => 1544804268.3668], 1);

        $this->assertStringNotMatchesFormat('<style>%A</style><script>%A</script>%A', $output->fetch(), 'styles & scripts are output only once');
    }

    /** * @dataProvider provideContext */
    
return ($this->prevErrorHandler)($type$msg$file$line$context);
            }

            return false;
        });
        $this->filter = $filter;

        if ($gc = gc_enabled()) {
            gc_disable();
        }
        try {
            return new Data($this->doClone($var));
        } finally {
            if ($gc) {
                gc_enable();
            }
            restore_error_handler();
            $this->prevErrorHandler = null;
        }
    }

    /** * Effectively clones the PHP variable. */
if (null !== $exception) {
            throw $exception;
        }
    }
}

class MockCloner implements ClonerInterface
{
    public function cloneVar($var): Data
    {
        return new Data([[$var.'-']]);
    }
}

class MockDumper implements DataDumperInterface
{
    public function dump(Data $data): ?string
    {
        echo '+'.$data->getValue();

        return null;
    }
}
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Server\Connection;

/** * @author Nicolas Grekas <p@tchwork.com> */
class DumpDataCollectorTest extends TestCase
{
    public function testDump()
    {
        $data = new Data([[123]]);
        $data = $data->withContext(['label' => 'foo']);

        $collector = new DumpDataCollector(null, new FileLinkFormatter([]));

        $this->assertSame('dump', $collector->getName());

        $collector->dump($data);
        $line = __LINE__ - 1;
        $this->assertSame(1, $collector->getDumpsCount());

        $dump = $collector->getDumps('html');
        

                }

                public function hasMetadataFor($classOrObject): bool
                {
                    return Data::class === $classOrObject;
                }
            })
            ->getValidator()
        ;

        $violations = $validator->validate(new Data()new Valid());

        $this->assertCount(2, $violations);
        $this->assertSame('custom message foo', $violations->get(0)->getMessage());
        $this->assertSame('This value should satisfy at least one of the following constraints: [1] custom message bar', $violations->get(1)->getMessage());
    }

    public function testNestedConstraintsAreNotExecutedWhenGroupDoesNotMatch()
    {
        $validator = Validation::createValidator();

        $violations = $validator->validate(50, new AtLeastOneOf([
            
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],
            ],
            [
                'bar' => 123,
            ]
        ]);

        
return ($this->prevErrorHandler)($type$msg$file$line$context);
            }

            return false;
        });
        $this->filter = $filter;

        if ($gc = gc_enabled()) {
            gc_disable();
        }
        try {
            return new Data($this->doClone($var));
        } finally {
            if ($gc) {
                gc_enable();
            }
            restore_error_handler();
            $this->prevErrorHandler = null;
        }
    }

    /** * Effectively clones the PHP variable. */


    /** * @dataProvider provideContext */
    public function testDescribe(array $context, string $expectedOutput, bool $decorated = false)
    {
        $output = new BufferedOutput();
        $output->setDecorated($decorated);
        $descriptor = new CliDescriptor(new CliDumper(fn ($s) => $s));

        $descriptor->describe($outputnew Data([[123]])$context + ['timestamp' => 1544804268.3668], 1);

        $this->assertStringMatchesFormat(trim($expectedOutput)str_replace(\PHP_EOL, "\n", trim($output->fetch())));
    }

    public static function provideContext()
    {
        yield 'source' => [
            [
                'source' => [
                    'name' => 'CliDescriptorTest.php',
                    'line' => 30,
                    
Home | Imprint | This part of the site doesn't use cookies.