Skip to content

Commit 23bf8ca

Browse files
authored
Fix tests. (#929)
* Fix tests.
1 parent 4624e94 commit 23bf8ca

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Db/Adapter/MysqlAdapter.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,24 @@ protected function afterClause(Column $column): string
607607
*/
608608
protected function getRenameColumnInstructions(string $tableName, string $columnName, string $newColumnName): AlterInstructions
609609
{
610+
$columns = $this->getColumns($tableName);
611+
$targetColumn = null;
612+
613+
foreach ($columns as $column) {
614+
if (strcasecmp($column->getName(), $columnName) === 0) {
615+
$targetColumn = $column;
616+
break;
617+
}
618+
}
619+
620+
if ($targetColumn === null) {
621+
throw new InvalidArgumentException(sprintf(
622+
"The specified column doesn't exist: %s",
623+
$columnName,
624+
));
625+
}
626+
627+
// Fetch raw MySQL column info for the full definition string
610628
$rows = $this->fetchAll(sprintf('SHOW FULL COLUMNS FROM %s', $this->quoteTableName($tableName)));
611629

612630
foreach ($rows as $row) {
@@ -624,8 +642,10 @@ static function ($value) {
624642
$extra = ' ' . implode(' ', $extras);
625643

626644
if (($row['Default'] !== null)) {
627-
$phinxTypeInfo = $this->getPhinxType($row['Type']);
628-
$extra .= $this->getDefaultValueDefinition($row['Default'], $phinxTypeInfo['name']);
645+
$columnType = $targetColumn->getType();
646+
// Column::getType() can return string|Literal, but getDefaultValueDefinition expects string|null
647+
$columnTypeName = is_string($columnType) ? $columnType : null;
648+
$extra .= $this->getDefaultValueDefinition($row['Default'], $columnTypeName);
629649
}
630650
$definition = $row['Type'] . ' ' . $null . $extra . $comment;
631651

tests/TestCase/Db/Adapter/AbstractAdapterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Migrations\Db\Literal;
1111
use Migrations\Test\TestCase\Db\Adapter\DefaultAdapterTrait;
1212
use PDOException;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314
use PHPUnit\Framework\TestCase;
1415
use RuntimeException;
1516

0 commit comments

Comments
 (0)