|
8 | 8 | use Doctrine\DBAL\Platforms\MariaDBPlatform; |
9 | 9 | use Doctrine\DBAL\Schema\AbstractSchemaManager; |
10 | 10 | use Doctrine\DBAL\Schema\Column; |
| 11 | +use Doctrine\DBAL\Schema\ColumnEditor; |
11 | 12 | use Doctrine\DBAL\Schema\Comparator; |
12 | 13 | use Doctrine\DBAL\Schema\ComparatorConfig; |
13 | 14 | use Doctrine\DBAL\Schema\Name\UnqualifiedName; |
|
17 | 18 | use Doctrine\DBAL\Types\Type; |
18 | 19 | use Doctrine\DBAL\Types\Types; |
19 | 20 | use PHPUnit\Framework\Attributes\DataProvider; |
| 21 | +use PHPUnit\Framework\Attributes\TestWith; |
20 | 22 |
|
21 | 23 | class ComparatorTest extends FunctionalTestCase |
22 | 24 | { |
@@ -61,6 +63,46 @@ public function testDefaultValueComparison(string $typeName, mixed $value): void |
61 | 63 | ); |
62 | 64 | } |
63 | 65 |
|
| 66 | + #[TestWith([Types::FLOAT])] |
| 67 | + #[TestWith([Types::SMALLFLOAT])] |
| 68 | + public function testFloatDefaultValueComparisonConverges(string $typeName): void |
| 69 | + { |
| 70 | + $table = Table::editor() |
| 71 | + ->setUnquotedName('float_default_value') |
| 72 | + ->setColumns( |
| 73 | + Column::editor() |
| 74 | + ->setUnquotedName('score') |
| 75 | + ->setTypeName($typeName) |
| 76 | + ->setDefaultValue(14.75) |
| 77 | + ->create(), |
| 78 | + ) |
| 79 | + ->create(); |
| 80 | + |
| 81 | + $this->dropAndCreateTable($table); |
| 82 | + |
| 83 | + $comparator = $this->schemaManager->createComparator(); |
| 84 | + |
| 85 | + self::assertTrue(ComparatorTestUtils::diffFromActualToDesiredTable( |
| 86 | + $this->schemaManager, |
| 87 | + $comparator, |
| 88 | + $table, |
| 89 | + )->isEmpty()); |
| 90 | + |
| 91 | + self::assertTrue(ComparatorTestUtils::diffFromDesiredToActualTable( |
| 92 | + $this->schemaManager, |
| 93 | + $comparator, |
| 94 | + $table, |
| 95 | + )->isEmpty()); |
| 96 | + |
| 97 | + $desiredTable = $table->edit() |
| 98 | + ->modifyColumnByUnquotedName('score', static function (ColumnEditor $editor): void { |
| 99 | + $editor->setDefaultValue(50.0); |
| 100 | + }) |
| 101 | + ->create(); |
| 102 | + |
| 103 | + ComparatorTestUtils::assertDiffNotEmpty($this->connection, $comparator, $desiredTable); |
| 104 | + } |
| 105 | + |
64 | 106 | public function testRenameColumnComparison(): void |
65 | 107 | { |
66 | 108 | $platform = $this->connection->getDatabasePlatform(); |
@@ -147,6 +189,9 @@ public static function defaultValueProvider(): iterable |
147 | 189 | { |
148 | 190 | return [ |
149 | 191 | [Types::INTEGER, 1], |
| 192 | + [Types::FLOAT, 14.75], |
| 193 | + [Types::FLOAT, '50.0'], |
| 194 | + [Types::SMALLFLOAT, 14.75], |
150 | 195 | [Types::BOOLEAN, false], |
151 | 196 | [Types::TEXT, 'Doctrine'], |
152 | 197 | ]; |
|
0 commit comments