|
20 | 20 | use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
21 | 21 | use Symfony\Bridge\Doctrine\Types\UlidType;
|
22 | 22 | use Symfony\Bridge\Doctrine\Types\UuidType;
|
| 23 | +use Symfony\Component\Form\Exception\TransformationFailedException; |
23 | 24 | use Symfony\Component\Uid\Uuid;
|
24 | 25 |
|
25 | 26 | class ORMQueryBuilderLoaderTest extends TestCase
|
@@ -188,6 +189,41 @@ public function testFilterUid($entityClass)
|
188 | 189 | $loader->getEntitiesByIds('id', ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d', '', 'b98e8e11-2897-44df-ad24-d2627eb7f499']);
|
189 | 190 | }
|
190 | 191 |
|
| 192 | + /** |
| 193 | + * @dataProvider provideUidEntityClasses |
| 194 | + */ |
| 195 | + public function testUidThrowProperException($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 = new ORMQueryBuilderLoader($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 | + |
191 | 227 | public function testEmbeddedIdentifierName()
|
192 | 228 | {
|
193 | 229 | if (Version::compare('2.5.0') > 0) {
|
|
0 commit comments