Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c8a6f9

Browse filesBrowse files
committed
bug #31874 [Doctrine Bridge] Check field type before adding Length constraint (belinde)
This PR was squashed before being merged into the 4.3 branch (closes #31874). Discussion ---------- [Doctrine Bridge] Check field type before adding Length constraint | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31855 | License | MIT | Doc PR | Validator\DoctrineLoader now add a Length constraint only on field of type string, text and guid; for any other type the mapping length is just ignored Commits ------- 35e6df6 [Doctrine Bridge] Check field type before adding Length constraint
2 parents 5777848 + 35e6df6 commit 9c8a6f9
Copy full SHA for 9c8a6f9

File tree

3 files changed

+20
-1
lines changed
Filter options

3 files changed

+20
-1
lines changed

‎src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoctrineLoaderEntity.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoctrineLoaderEntity.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ class DoctrineLoaderEntity extends DoctrineLoaderParentEntity
6060
* @ORM\Embedded(class=DoctrineLoaderEmbed::class)
6161
*/
6262
public $embedded;
63+
64+
/** @ORM\Column(type="text", nullable=true, length=1000) */
65+
public $textField;
66+
67+
/** @ORM\Id @ORM\Column(type="guid", length=50) */
68+
protected $guidField;
69+
70+
/** @ORM\Column(type="simple_array", length=100) */
71+
public $simpleArrayField = [];
6372
}

‎src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ public function testLoadClassMetadata()
108108
$this->assertCount(1, $embeddedMaxLengthConstraints);
109109
$this->assertInstanceOf(Length::class, $embeddedMaxLengthConstraints[0]);
110110
$this->assertSame(25, $embeddedMaxLengthConstraints[0]->max);
111+
112+
$this->assertCount(0, $classMetadata->getPropertyMetadata('guidField'));
113+
$this->assertCount(0, $classMetadata->getPropertyMetadata('simpleArrayField'));
114+
115+
$textFieldMetadata = $classMetadata->getPropertyMetadata('textField');
116+
$this->assertCount(1, $textFieldMetadata);
117+
$textFieldConstraints = $textFieldMetadata[0]->getConstraints();
118+
$this->assertCount(1, $textFieldConstraints);
119+
$this->assertInstanceOf(Length::class, $textFieldConstraints[0]);
120+
$this->assertSame(1000, $textFieldConstraints[0]->max);
111121
}
112122

113123
public function testFieldMappingsConfiguration()

‎src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
7373
$metadata->addConstraint(new UniqueEntity(['fields' => $mapping['fieldName']]));
7474
}
7575

76-
if (null === ($mapping['length'] ?? null)) {
76+
if (null === ($mapping['length'] ?? null) || !\in_array($mapping['type'], ['string', 'text'], true)) {
7777
continue;
7878
}
7979

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.