Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit730b2a5

Browse files
committed
bug#39417 [Form] Fix UUID exception (jderusse)
This PR was merged into the 5.2 branch.Discussion----------[Form] Fix UUID exception| Q | A| ------------- | ---| Branch? | 5.2| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#39407| License | MIT| Doc PR | -When submitting an invalid UUID, the exception thrown by `Form\ChoiceList\ORMQueryBuilderLoader` should be a `TransformationFailedException` in order to be properly intercepted by the `Form\Form` classCommits-------a41e7f0 Fix exception thrown by Form when converting UUID
2 parentse974752 +a41e7f0 commit730b2a5

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

‎src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
namespaceSymfony\Bridge\Doctrine\Form\ChoiceList;
1313

1414
useDoctrine\DBAL\Connection;
15+
useDoctrine\DBAL\Types\ConversionException;
1516
useDoctrine\DBAL\Types\Type;
1617
useDoctrine\ORM\QueryBuilder;
18+
useSymfony\Component\Form\Exception\TransformationFailedException;
1719

1820
/**
1921
* Loads entities using a {@link QueryBuilder} instance.
@@ -96,7 +98,11 @@ public function getEntitiesByIds(string $identifier, array $values)
9698
$doctrineType = Type::getType($type);
9799
$platform =$qb->getEntityManager()->getConnection()->getDatabasePlatform();
98100
foreach ($valuesas &$value) {
99-
$value =$doctrineType->convertToDatabaseValue($value,$platform);
101+
try {
102+
$value =$doctrineType->convertToDatabaseValue($value,$platform);
103+
}catch (ConversionException$e) {
104+
thrownewTransformationFailedException(sprintf('Failed to transform "%s" into "%s".',$value,$type),0,$e);
105+
}
100106
}
101107
unset($value);
102108
}

‎src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
useSymfony\Bridge\Doctrine\Test\DoctrineTestHelper;
2121
useSymfony\Bridge\Doctrine\Types\UlidType;
2222
useSymfony\Bridge\Doctrine\Types\UuidType;
23+
useSymfony\Component\Form\Exception\TransformationFailedException;
2324
useSymfony\Component\Uid\Uuid;
2425

2526
class ORMQueryBuilderLoaderTestextends TestCase
@@ -188,6 +189,41 @@ public function testFilterUid($entityClass)
188189
$loader->getEntitiesByIds('id', ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d','','b98e8e11-2897-44df-ad24-d2627eb7f499']);
189190
}
190191

192+
/**
193+
* @dataProvider provideUidEntityClasses
194+
*/
195+
publicfunctiontestUidThrowProperException($entityClass)
196+
{
197+
if (Type::hasType('uuid')) {
198+
Type::overrideType('uuid', UuidType::class);
199+
}else {
200+
Type::addType('uuid', UuidType::class);
201+
}
202+
if (!Type::hasType('ulid')) {
203+
Type::addType('ulid', UlidType::class);
204+
}
205+
206+
$em = DoctrineTestHelper::createTestEntityManager();
207+
208+
$qb =$this->getMockBuilder('Doctrine\ORM\QueryBuilder')
209+
->setConstructorArgs([$em])
210+
->setMethods(['getQuery'])
211+
->getMock();
212+
213+
$qb->expects($this->never())
214+
->method('getQuery');
215+
216+
$qb->select('e')
217+
->from($entityClass,'e');
218+
219+
$loader =newORMQueryBuilderLoader($qb);
220+
221+
$this->expectException(TransformationFailedException::class);
222+
$this->expectExceptionMessageMatches('/^Failed to transform "hello" into "(uuid|ulid)"\.$/');
223+
224+
$loader->getEntitiesByIds('id', ['hello']);
225+
}
226+
191227
publicfunctiontestEmbeddedIdentifierName()
192228
{
193229
if (Version::compare('2.5.0') >0) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp