|
13 | 13 | use Doctrine\DBAL\Schema\PrimaryKeyConstraint; |
14 | 14 | use Doctrine\DBAL\Schema\PrimaryKeyConstraintEditor; |
15 | 15 | use Doctrine\DBAL\Schema\Table as DbalTable; |
| 16 | +use Doctrine\DBAL\Types\EnumType; |
| 17 | +use Doctrine\DBAL\Types\Types; |
16 | 18 | use Doctrine\ORM\Mapping\ClassMetadata; |
17 | 19 | use Doctrine\ORM\Mapping\Column; |
18 | 20 | use Doctrine\ORM\Mapping\Entity; |
|
46 | 48 | use Doctrine\Tests\Models\Enums\Suit; |
47 | 49 | use Doctrine\Tests\Models\Forum\ForumAvatar; |
48 | 50 | use Doctrine\Tests\Models\Forum\ForumUser; |
| 51 | +use Doctrine\Tests\Models\GH10288\GH10288People; |
49 | 52 | use Doctrine\Tests\Models\NullDefault\NullDefaultColumn; |
50 | 53 | use Doctrine\Tests\OrmTestCase; |
51 | 54 | use PHPUnit\Framework\Attributes\Group; |
@@ -272,6 +275,38 @@ public function testSetDiscriminatorColumnWithoutLength(): void |
272 | 275 | self::assertEquals(255, $column->getLength()); |
273 | 276 | } |
274 | 277 |
|
| 278 | + public function testSetDiscriminatorColumnWithEnumType(): void |
| 279 | + { |
| 280 | + if (! class_exists(EnumType::class)) { |
| 281 | + self::markTestSkipped('Test valid for doctrine/dbal versions with EnumType only.'); |
| 282 | + } |
| 283 | + |
| 284 | + $em = $this->getTestEntityManager(); |
| 285 | + $schemaTool = new SchemaTool($em); |
| 286 | + $metadata = $em->getClassMetadata(FirstEntity::class); |
| 287 | + |
| 288 | + $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); |
| 289 | + $metadata->setDiscriminatorColumn([ |
| 290 | + 'name' => 'discriminator', |
| 291 | + 'type' => Types::ENUM, |
| 292 | + 'enumType' => GH10288People::class, |
| 293 | + ]); |
| 294 | + |
| 295 | + $schema = $schemaTool->getSchemaFromMetadata([$metadata]); |
| 296 | + |
| 297 | + self::assertTrue($schema->hasTable('first_entity')); |
| 298 | + $table = $schema->getTable('first_entity'); |
| 299 | + |
| 300 | + self::assertTrue($table->hasColumn('discriminator')); |
| 301 | + $column = $table->getColumn('discriminator'); |
| 302 | + self::assertEquals(GH10288People::class, $column->getPlatformOption('enumType')); |
| 303 | + self::assertEquals([0 => 'boss', 1 => 'employee'], $column->getValues()); |
| 304 | + |
| 305 | + $this->expectException(MappingException::class); |
| 306 | + $this->expectExceptionMessage("The entries 'user' in the discriminator map of class '" . FirstEntity::class . "' do not correspond to enum cases of '" . GH10288People::class . "'."); |
| 307 | + $metadata->setDiscriminatorMap(['user' => CmsUser::class, 'employee' => CmsEmployee::class]); |
| 308 | + } |
| 309 | + |
275 | 310 | public function testDerivedCompositeKey(): void |
276 | 311 | { |
277 | 312 | $em = $this->getTestEntityManager(); |
|
0 commit comments