Skip to content

Commit 6fc2230

Browse files
authored
Make all mapped database types case insensitive (#6321)
<!-- Fill in the relevant information below to help triage your pull request. --> | Q | A |------------- | ----------- | Type | improvement | Fixed issues | <!-- use #NUM format to reference an issue --> #### Summary <!-- Provide a summary of your change. --> Currently, a custom mapping type has to return an array of lowercase strings in `getMappedDatabaseTypes` or else Doctrine fails to retrieve the added type as both `AbstractPlatform::getDoctrineTypeMapping` and `AbstractPlatform::hasDoctrineTypeMappingFor` do a lowercase conversion before the look-up. A devolper should not depend on internal representation. This PR addresses this by storing the mapped type in lowercase to `AbstractPlatform#doctrineTypeMapping`. This is in line with `AbstractPlatform::registerDoctrineTypeMapping`, which does a lowercase conversion as well.
1 parent b4329d5 commit 6fc2230

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Platforms/AbstractPlatform.php

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ private function initializeAllDoctrineTypeMappings(): void
213213

214214
foreach (Type::getTypesMap() as $typeName => $className) {
215215
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) {
216+
$dbType = strtolower($dbType);
216217
$this->doctrineTypeMapping[$dbType] = $typeName;
217218
}
218219
}

tests/Platforms/AbstractPlatformTestCase.php

+34
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,40 @@ public function testRegisterDoctrineMappingType(): void
106106
self::assertEquals(Types::INTEGER, $this->platform->getDoctrineTypeMapping('foo'));
107107
}
108108

109+
public function testCaseInsensitiveDoctrineTypeMappingFromType(): void
110+
{
111+
$type = new class () extends Type {
112+
/**
113+
* {@inheritDoc}
114+
*/
115+
public function getMappedDatabaseTypes(AbstractPlatform $platform): array
116+
{
117+
return ['TESTTYPE'];
118+
}
119+
120+
public function getName(): string
121+
{
122+
return 'testtype';
123+
}
124+
125+
/**
126+
* {@inheritDoc}
127+
*/
128+
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
129+
{
130+
return $platform->getDecimalTypeDeclarationSQL($column);
131+
}
132+
};
133+
134+
if (Type::hasType($type->getName())) {
135+
Type::overrideType($type->getName(), get_class($type));
136+
} else {
137+
Type::addType($type->getName(), get_class($type));
138+
}
139+
140+
self::assertSame($type->getName(), $this->platform->getDoctrineTypeMapping('TeStTyPe'));
141+
}
142+
109143
public function testRegisterUnknownDoctrineMappingType(): void
110144
{
111145
$this->expectException(Exception::class);

0 commit comments

Comments
 (0)