setUpVarDumper example

use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

/** * @author Maxime Steinhausser <maxime.steinhausser@gmail.com> */
class ContextTest extends TestCase
{
    use VarDumperTestTrait;

    protected function setUp(): void
    {
        $this->setUpVarDumper([], CliDumper::DUMP_LIGHT_ARRAY | CliDumper::DUMP_TRAILING_COMMA);
    }

    public function testThrowsOnEmptyContext()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('At least one of the "context", "normalizationContext", or "denormalizationContext" options of annotation "Symfony\Component\Serializer\Annotation\Context" must be provided as a non-empty array.');

        new Context();
    }

    public function testInvalidGroupOption()
    {
$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 {
                $stub->class = 'DateTimeImmutable';

                return ['date' => $date->format('d/m/Y')];
            },
        ], CliDumper::DUMP_LIGHT_ARRAY | CliDumper::DUMP_COMMA_SEPARATOR);

        $this->assertSame(CliDumper::DUMP_LIGHT_ARRAY | CliDumper::DUMP_COMMA_SEPARATOR, $this->varDumperConfig['flags']);
        $this->assertSame($casters$this->varDumperConfig['casters']);

        $this->assertDumpEquals(<<<DUMP
Home | Imprint | This part of the site doesn't use cookies.