addMetadata example

use Symfony\Component\Validator\Mapping\TraversalStrategy;
use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory;
use Symfony\Component\Validator\Validation;

class ValidatorExtensionTest extends TestCase
{
    public function test2Dot5ValidationApi()
    {
        $metadata = new ClassMetadata(Form::class);

        $metadataFactory = new FakeMetadataFactory();
        $metadataFactory->addMetadata($metadata);

        $validator = Validation::createValidatorBuilder()
            ->setMetadataFactory($metadataFactory)
            ->getValidator();

        $extension = new ValidatorExtension($validator, false);

        $this->assertInstanceOf(ValidatorTypeGuesser::class$extension->loadTypeGuesser());

        $this->assertCount(1, $metadata->getConstraints());
        $this->assertInstanceOf(FormConstraint::class$metadata->getConstraints()[0]);

        
private FakeMetadataFactory $metadataFactory;
    private ClassMetadata $metadata;
    private ClassMetadata $referenceMetadata;
    private ValidatorInterface $validator;

    protected function setUp(): void
    {
        $this->metadataFactory = new FakeMetadataFactory();
        $this->metadata = new ClassMetadata(self::ENTITY_CLASS);
        $this->referenceMetadata = new ClassMetadata(self::REFERENCE_CLASS);
        $this->metadataFactory->addMetadata($this->metadata);
        $this->metadataFactory->addMetadata($this->referenceMetadata);
        $this->metadataFactory->addMetadata(new ClassMetadata(LazyProperty::class));

        $this->validator = $this->createValidator($this->metadataFactory);
    }

    protected function validate($value$constraints = null, $groups = null)
    {
        return $this->validator->validate($value$constraints$groups);
    }

    
$messages = array_diff_key($messages$intlMessages);
            }
            $this->add($messages$domain);
        }

        foreach ($catalogue->getResources() as $resource) {
            $this->addResource($resource);
        }

        if ($catalogue instanceof MetadataAwareInterface) {
            $metadata = $catalogue->getMetadata('', '');
            $this->addMetadata($metadata);
        }

        if ($catalogue instanceof CatalogueMetadataAwareInterface) {
            $catalogueMetadata = $catalogue->getCatalogueMetadata('', '');
            $this->addCatalogueMetadata($catalogueMetadata);
        }
    }

    /** * @return void */
    
private ClassMetadata $metadata;

    /** * @var MetadataFactoryInterface */
    private \Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory $metadataFactory;

    protected function setUp(): void
    {
        $this->metadata = new ClassMetadata(self::TEST_CLASS);
        $this->metadataFactory = new FakeMetadataFactory();
        $this->metadataFactory->addMetadata($this->metadata);
        $this->guesser = new ValidatorTypeGuesser($this->metadataFactory);
    }

    /** * @dataProvider guessTypeProvider */
    public function testGuessType(Constraint $constraint, TypeGuess $guess)
    {
        $this->metadata->addPropertyConstraint(self::TEST_PROPERTY, $constraint);

        $this->assertEquals($guess$this->guesser->guessType(self::TEST_CLASS, self::TEST_PROPERTY));
    }
$code = '';

        foreach ($places as $id => $place) {
            if (isset($place['attributes']['name'])) {
                $placeName = $place['attributes']['name'];
                unset($place['attributes']['name']);
            } else {
                $placeName = $id;
            }

            if ($withMetadata) {
                $escapedLabel = sprintf('<<B>%s</B>%s>', $this->escape($placeName)$this->addMetadata($place['attributes']['metadata']));
                // Don't include metadata in default attributes used to format the place                 unset($place['attributes']['metadata']);
            } else {
                $escapedLabel = sprintf('"%s"', $this->escape($placeName));
            }

            $code .= sprintf(" place_%s [label=%s, shape=circle%s];\n", $this->dotize($id)$escapedLabel$this->addAttributes($place['attributes']));
        }

        return $code;
    }

    
Home | Imprint | This part of the site doesn't use cookies.