|
12 | 12 | namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
13 | 13 |
|
14 | 14 | use Doctrine\DBAL\Connection;
|
| 15 | +use Doctrine\DBAL\Types\GuidType; |
| 16 | +use Doctrine\DBAL\Types\Type; |
15 | 17 | use Doctrine\ORM\Version;
|
16 | 18 | use PHPUnit\Framework\TestCase;
|
17 | 19 | use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
18 | 20 | use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
| 21 | +use Symfony\Bridge\Doctrine\Types\UlidType; |
| 22 | +use Symfony\Bridge\Doctrine\Types\UuidType; |
| 23 | +use Symfony\Component\Uid\Uuid; |
19 | 24 |
|
20 | 25 | class ORMQueryBuilderLoaderTest extends TestCase
|
21 | 26 | {
|
| 27 | + protected function tearDown(): void |
| 28 | + { |
| 29 | + if (Type::hasType('uuid')) { |
| 30 | + Type::overrideType('uuid', GuidType::class); |
| 31 | + } |
| 32 | + } |
| 33 | + |
22 | 34 | public function testIdentifierTypeIsStringArray()
|
23 | 35 | {
|
24 | 36 | $this->checkIdentifierType('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity', Connection::PARAM_STR_ARRAY);
|
@@ -131,6 +143,51 @@ public function testFilterEmptyUuids($entityClass)
|
131 | 143 | $loader->getEntitiesByIds('id', ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d', '', 'b98e8e11-2897-44df-ad24-d2627eb7f499']);
|
132 | 144 | }
|
133 | 145 |
|
| 146 | + /** |
| 147 | + * @dataProvider provideUidEntityClasses |
| 148 | + */ |
| 149 | + public function testFilterUid($entityClass) |
| 150 | + { |
| 151 | + if (Type::hasType('uuid')) { |
| 152 | + Type::overrideType('uuid', UuidType::class); |
| 153 | + } else { |
| 154 | + Type::addType('uuid', UuidType::class); |
| 155 | + } |
| 156 | + if (!Type::hasType('ulid')) { |
| 157 | + Type::addType('ulid', UlidType::class); |
| 158 | + } |
| 159 | + |
| 160 | + $em = DoctrineTestHelper::createTestEntityManager(); |
| 161 | + |
| 162 | + $query = $this->getMockBuilder('QueryMock') |
| 163 | + ->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute']) |
| 164 | + ->getMock(); |
| 165 | + |
| 166 | + $query |
| 167 | + ->method('getResult') |
| 168 | + ->willReturn([]); |
| 169 | + |
| 170 | + $query->expects($this->once()) |
| 171 | + ->method('setParameter') |
| 172 | + ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [Uuid::fromString('71c5fd46-3f16-4abb-bad7-90ac1e654a2d')->toBinary(), Uuid::fromString('b98e8e11-2897-44df-ad24-d2627eb7f499')->toBinary()], Connection::PARAM_STR_ARRAY) |
| 173 | + ->willReturn($query); |
| 174 | + |
| 175 | + $qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') |
| 176 | + ->setConstructorArgs([$em]) |
| 177 | + ->setMethods(['getQuery']) |
| 178 | + ->getMock(); |
| 179 | + |
| 180 | + $qb->expects($this->once()) |
| 181 | + ->method('getQuery') |
| 182 | + ->willReturn($query); |
| 183 | + |
| 184 | + $qb->select('e') |
| 185 | + ->from($entityClass, 'e'); |
| 186 | + |
| 187 | + $loader = new ORMQueryBuilderLoader($qb); |
| 188 | + $loader->getEntitiesByIds('id', ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d', '', 'b98e8e11-2897-44df-ad24-d2627eb7f499']); |
| 189 | + } |
| 190 | + |
134 | 191 | public function testEmbeddedIdentifierName()
|
135 | 192 | {
|
136 | 193 | if (Version::compare('2.5.0') > 0) {
|
@@ -176,4 +233,12 @@ public function provideGuidEntityClasses()
|
176 | 233 | ['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'],
|
177 | 234 | ];
|
178 | 235 | }
|
| 236 | + |
| 237 | + public function provideUidEntityClasses() |
| 238 | + { |
| 239 | + return [ |
| 240 | + ['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'], |
| 241 | + ['Symfony\Bridge\Doctrine\Tests\Fixtures\UlidIdEntity'], |
| 242 | + ]; |
| 243 | + } |
179 | 244 | }
|
0 commit comments