Skip to content

Commit 252b19a

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

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/Types/Exception/UnknownColumnType.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\DBAL\Types\Exception;
66

77
use Exception;
8+
use Throwable;
89

910
use function sprintf;
1011

@@ -35,19 +36,22 @@ public static function new(string $name): self
3536
return $object;
3637
}
3738

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

5256
$object->requestedType = $name;
5357

tests/Schema/ColumnEditorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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;
@@ -78,4 +79,17 @@ public function testTypeNotSet(): void
7879

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

0 commit comments

Comments
 (0)