Skip to content

Commit

Permalink
Make all mapped database types case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Rainrider authored and derrabus committed Mar 3, 2024
1 parent b4329d5 commit e0986c7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ private function initializeAllDoctrineTypeMappings(): void

foreach (Type::getTypesMap() as $typeName => $className) {
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) {
$dbType = strtolower($dbType);
$this->doctrineTypeMapping[$dbType] = $typeName;
}
}
Expand Down
34 changes: 34 additions & 0 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ public function testRegisterDoctrineMappingType(): void
self::assertEquals(Types::INTEGER, $this->platform->getDoctrineTypeMapping('foo'));
}

public function testCaseInsensitiveDoctrineTypeMappingFromType(): void
{
$type = new class () extends Type {
/**
* {@inheritDoc}
*/
public function getMappedDatabaseTypes(AbstractPlatform $platform): array
{
return ['TESTTYPE'];
}

public function getName(): string
{
return 'testtype';
}

/**
* {@inheritDoc}
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return $platform->getDecimalTypeDeclarationSQL($column);
}
};

if (Type::hasType($type->getName())) {
Type::overrideType($type->getName(), get_class($type));
} else {
Type::addType($type->getName(), get_class($type));
}

self::assertSame($type->getName(), $this->platform->getDoctrineTypeMapping('TeStTyPe'));
}

public function testRegisterUnknownDoctrineMappingType(): void
{
$this->expectException(Exception::class);
Expand Down

0 comments on commit e0986c7

Please sign in to comment.