Skip to content
Permalink
Browse files

[Doctrine Bridge] Check field type before adding Length constraint

  • Loading branch information...
belinde authored and xabbuh committed Jun 5, 2019
1 parent e5b082a commit 35e6df6bac3bbb35f71c57771ecf1dbbc510af38
@@ -60,4 +60,13 @@ class DoctrineLoaderEntity extends DoctrineLoaderParentEntity
* @ORM\Embedded(class=DoctrineLoaderEmbed::class)
*/
public $embedded;
/** @ORM\Column(type="text", nullable=true, length=1000) */
public $textField;
/** @ORM\Id @ORM\Column(type="guid", length=50) */
protected $guidField;
/** @ORM\Column(type="simple_array", length=100) */
public $simpleArrayField = [];
}
@@ -108,6 +108,16 @@ public function testLoadClassMetadata()
$this->assertCount(1, $embeddedMaxLengthConstraints);
$this->assertInstanceOf(Length::class, $embeddedMaxLengthConstraints[0]);
$this->assertSame(25, $embeddedMaxLengthConstraints[0]->max);
$this->assertCount(0, $classMetadata->getPropertyMetadata('guidField'));
$this->assertCount(0, $classMetadata->getPropertyMetadata('simpleArrayField'));
$textFieldMetadata = $classMetadata->getPropertyMetadata('textField');
$this->assertCount(1, $textFieldMetadata);
$textFieldConstraints = $textFieldMetadata[0]->getConstraints();
$this->assertCount(1, $textFieldConstraints);
$this->assertInstanceOf(Length::class, $textFieldConstraints[0]);
$this->assertSame(1000, $textFieldConstraints[0]->max);
}
public function testFieldMappingsConfiguration()
@@ -73,7 +73,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
$metadata->addConstraint(new UniqueEntity(['fields' => $mapping['fieldName']]));
}
if (null === ($mapping['length'] ?? null)) {
if (null === ($mapping['length'] ?? null) || !\in_array($mapping['type'], ['string', 'text'], true)) {
continue;
}

0 comments on commit 35e6df6

Please sign in to comment.
You can’t perform that action at this time.