enableAnnotationMapping example

use Doctrine\Common\Annotations\Reader;
use Shopware\Bundle\FormBundle\DependencyInjection\Factory\ConstraintValidatorFactory;
use Symfony\Component\Validator\Validation;

class Validator
{
    public static function create(Reader $annotationsReader, ConstraintValidatorFactory $validatorFactory)
    {
        $validatorBuilder = Validation::createValidatorBuilder();

        $validatorBuilder->enableAnnotationMapping($annotationsReader);
        $validatorBuilder->setConstraintValidatorFactory($validatorFactory);

        return $validatorBuilder->getValidator();
    }
}

class FlowTemplateConfigFieldSerializerTest extends TestCase
{
    private FlowTemplateConfigFieldSerializer $serializer;

    protected function setUp(): void
    {
        parent::setUp();

        $validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
        $definitionRegistry = $this->createMock(DefinitionInstanceRegistry::class);

        $this->serializer = new FlowTemplateConfigFieldSerializer($validator$definitionRegistry);
    }

    public function testSerializeWithInvalidConfigArray(): void
    {
        static::expectException(WriteConstraintViolationException::class);

        $this->encode([
            'eventName' => 111,
            
public function testAddMethodMappings()
    {
        $this->assertSame($this->builder, $this->builder->addMethodMappings([]));
    }

    /** * @group legacy */
    public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader()
    {
        $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::enableAnnotationMapping()" is deprecated, use "enableAttributeMapping()" instead.');
        $this->assertSame($this->builder, $this->builder->enableAnnotationMapping());

        $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::addDefaultDoctrineAnnotationReader()" is deprecated without replacement.');
        $this->assertSame($this->builder, $this->builder->addDefaultDoctrineAnnotationReader());

        $loaders = $this->builder->getLoaders();
        $this->assertCount(1, $loaders);
        $this->assertInstanceOf(AnnotationLoader::class$loaders[0]);

        $r = new \ReflectionProperty(AnnotationLoader::class, 'reader');

        $this->assertInstanceOf(PsrCachedReader::class$r->getValue($loaders[0]));
    }
Home | Imprint | This part of the site doesn't use cookies.