diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php index efefb28f85bba..e38a7268be623 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php @@ -12,8 +12,10 @@ namespace Symfony\Bridge\Doctrine\Form\ChoiceList; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\QueryBuilder; +use Symfony\Component\Form\Exception\TransformationFailedException; /** * Loads entities using a {@link QueryBuilder} instance. @@ -96,7 +98,11 @@ public function getEntitiesByIds(string $identifier, array $values) $doctrineType = Type::getType($type); $platform = $qb->getEntityManager()->getConnection()->getDatabasePlatform(); foreach ($values as &$value) { - $value = $doctrineType->convertToDatabaseValue($value, $platform); + try { + $value = $doctrineType->convertToDatabaseValue($value, $platform); + } catch (ConversionException $e) { + throw new TransformationFailedException(sprintf('Failed to transform "%s" into "%s".', $value, $type), 0, $e); + } } unset($value); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php index 1702532aa699e..caebae184848f 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php @@ -20,6 +20,7 @@ use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; use Symfony\Bridge\Doctrine\Types\UlidType; use Symfony\Bridge\Doctrine\Types\UuidType; +use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Uid\Uuid; class ORMQueryBuilderLoaderTest extends TestCase @@ -188,6 +189,41 @@ public function testFilterUid($entityClass) $loader->getEntitiesByIds('id', ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d', '', 'b98e8e11-2897-44df-ad24-d2627eb7f499']); } + /** + * @dataProvider provideUidEntityClasses + */ + public function testUidThrowProperException($entityClass) + { + if (Type::hasType('uuid')) { + Type::overrideType('uuid', UuidType::class); + } else { + Type::addType('uuid', UuidType::class); + } + if (!Type::hasType('ulid')) { + Type::addType('ulid', UlidType::class); + } + + $em = DoctrineTestHelper::createTestEntityManager(); + + $qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') + ->setConstructorArgs([$em]) + ->setMethods(['getQuery']) + ->getMock(); + + $qb->expects($this->never()) + ->method('getQuery'); + + $qb->select('e') + ->from($entityClass, 'e'); + + $loader = new ORMQueryBuilderLoader($qb); + + $this->expectException(TransformationFailedException::class); + $this->expectExceptionMessageMatches('/^Failed to transform "hello" into "(uuid|ulid)"\.$/'); + + $loader->getEntitiesByIds('id', ['hello']); + } + public function testEmbeddedIdentifierName() { if (Version::compare('2.5.0') > 0) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy