DoctrineLoader example

use Symfony\Component\Validator\Validation;

/** * @author Kévin Dunglas <dunglas@gmail.com> */
class DoctrineLoaderTest extends TestCase
{
    public function testLoadClassMetadata()
    {
        $validator = Validation::createValidatorBuilder()
            ->enableAttributeMapping()
            ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}'))
            ->getValidator()
        ;

        $classMetadata = $validator->getMetadataFor(new DoctrineLoaderEntity());

        $classConstraints = $classMetadata->getConstraints();
        $this->assertCount(2, $classConstraints);
        $this->assertInstanceOf(UniqueEntity::class$classConstraints[0]);
        $this->assertInstanceOf(UniqueEntity::class$classConstraints[1]);
        $this->assertSame(['alreadyMappedUnique']$classConstraints[0]->fields);
        $this->assertSame('unique', $classConstraints[1]->fields);

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