ModernPerson example

public function testBundleValidationConfigDir()
    {
        static::bootKernel(['test_case' => 'BundlePaths']);
        $validator = static::getContainer()->get('validator.alias');

        $this->assertTrue($validator->hasMetadataFor(LegacyPerson::class));
        $this->assertCount(1, $constraintViolationList = $validator->validate(new LegacyPerson('john', 5)));
        $this->assertSame('This value should be greater than 18.', $constraintViolationList->get(0)->getMessage());

        $this->assertTrue($validator->hasMetadataFor(ModernPerson::class));
        $this->assertCount(1, $constraintViolationList = $validator->validate(new ModernPerson('john', 5)));
        $this->assertSame('This value should be greater than 18.', $constraintViolationList->get(0)->getMessage());
    }

    public function testBundleSerializationConfigDir()
    {
        static::bootKernel(['test_case' => 'BundlePaths']);
        $serializer = static::getContainer()->get('serializer.alias');

        $this->assertEquals(['full_name' => 'john', 'age' => 5]$serializer->normalize(new LegacyPerson('john', 5), 'json'));
        $this->assertEquals(['full_name' => 'john', 'age' => 5]$serializer->normalize(new ModernPerson('john', 5), 'json'));
    }
}
Home | Imprint | This part of the site doesn't use cookies.