Skip to content

Commit f85c621

Browse files
committed
Adding tests for unknown colum type
1 parent 9caaba3 commit f85c621

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/Types/Exception/UnknownColumnType.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,22 @@ public static function new(string $name): self
3535
return $object;
3636
}
3737

38-
public static function newWithContext(string $name, string $tableName): self
38+
public static function newWithContext(string $name, string $tableName, ?\Throwable $previous): self
3939
{
40-
$object = new self(sprintf(
41-
'Unknown column type "%s" requested for table "%s". Any Doctrine type that you use has '
40+
$object = new self(
41+
sprintf(
42+
'Unknown column type "%s" requested for table "%s". Any Doctrine type that you use has '
4243
. 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the '
4344
. 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database '
4445
. 'introspection then you might have forgotten to register all database types for a Doctrine Type. '
4546
. 'Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement '
4647
. 'Type#getMappedDatabaseTypes(). If the type name is empty you might '
4748
. 'have a problem with the cache or forgot some mapping information.',
48-
$name,
49-
$tableName,
50-
));
49+
$name,
50+
$tableName,
51+
),
52+
previous: $previous
53+
);
5154

5255
$object->requestedType = $name;
5356

tests/Schema/ColumnEditorTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
use Doctrine\DBAL\Schema\Column;
88
use Doctrine\DBAL\Schema\Exception\InvalidColumnDefinition;
99
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
10+
use Doctrine\DBAL\Types\Exception\UnknownColumnType;
1011
use Doctrine\DBAL\Types\IntegerType;
1112
use Doctrine\DBAL\Types\Type;
1213
use Doctrine\DBAL\Types\Types;
1314
use PHPUnit\Framework\TestCase;
14-
1515
class ColumnEditorTest extends TestCase
1616
{
1717
public function testSetUnquotedName(): void
@@ -78,4 +78,17 @@ public function testTypeNotSet(): void
7878

7979
$editor->create();
8080
}
81+
public function testInvalidType(): void
82+
{
83+
$this->expectException(UnknownColumnType::class);
84+
$this->expectExceptionMessage('Unknown column type "unknown_type"');
85+
86+
Column::editor()
87+
->setUnquotedName('column_char')
88+
->setTypeName('unknown_type')
89+
->setFixed(true)
90+
->setLength(2)
91+
->create();
92+
93+
}
8194
}

0 commit comments

Comments
 (0)