|
6 | 6 |
|
7 | 7 | use Doctrine\DBAL\Exception;
|
8 | 8 | use Doctrine\DBAL\Exception\InvalidColumnDeclaration;
|
| 9 | +use Doctrine\DBAL\Exception\InvalidColumnType\ColumnValuesRequired; |
9 | 10 | use Doctrine\DBAL\Platforms\AbstractPlatform;
|
10 | 11 | use Doctrine\DBAL\Schema\Column;
|
11 | 12 | use Doctrine\DBAL\Schema\ColumnDiff;
|
@@ -1030,4 +1031,38 @@ public static function asciiStringSqlDeclarationDataProvider(): array
|
1030 | 1031 | ['CHAR(12)', ['length' => 12, 'fixed' => true]],
|
1031 | 1032 | ];
|
1032 | 1033 | }
|
| 1034 | + |
| 1035 | + /** @param array<string> $values */ |
| 1036 | + #[DataProvider('getEnumDeclarationSQLProvider')] |
| 1037 | + public function testGetEnumDeclarationSQL(array $values, string $expectedSQL): void |
| 1038 | + { |
| 1039 | + self::assertSame($expectedSQL, $this->platform->getEnumDeclarationSQL(['values' => $values])); |
| 1040 | + } |
| 1041 | + |
| 1042 | + /** @return array<string, array{array<string>, string}> */ |
| 1043 | + public static function getEnumDeclarationSQLProvider(): array |
| 1044 | + { |
| 1045 | + return [ |
| 1046 | + 'single value' => [['foo'], 'VARCHAR(3)'], |
| 1047 | + 'multiple values' => [['foo', 'bar1'], 'VARCHAR(4)'], |
| 1048 | + ]; |
| 1049 | + } |
| 1050 | + |
| 1051 | + /** @param array<mixed> $column */ |
| 1052 | + #[DataProvider('getEnumDeclarationSQLWithInvalidValuesProvider')] |
| 1053 | + public function testGetEnumDeclarationSQLWithInvalidValues(array $column): void |
| 1054 | + { |
| 1055 | + self::expectException(ColumnValuesRequired::class); |
| 1056 | + $this->platform->getEnumDeclarationSQL($column); |
| 1057 | + } |
| 1058 | + |
| 1059 | + /** @return array<string, array{array<mixed>}> */ |
| 1060 | + public static function getEnumDeclarationSQLWithInvalidValuesProvider(): array |
| 1061 | + { |
| 1062 | + return [ |
| 1063 | + "field 'values' does not exist" => [[]], |
| 1064 | + "field 'values' is not an array" => [['values' => 'foo']], |
| 1065 | + "field 'values' is an empty array" => [['values' => []]], |
| 1066 | + ]; |
| 1067 | + } |
1033 | 1068 | }
|
0 commit comments