Skip to content

Commit

Permalink
Add rename loop case
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Aug 29, 2023
1 parent 09a504b commit d27d676
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ final public function renameColumn(string $oldName, string $newName): Column
unset($this->renamedColumns[$toRemove]);
}

$this->renamedColumns[$newName] = $oldName;
if ($newName !== $oldName) {
$this->renamedColumns[$newName] = $oldName;
}

return $column;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Schema/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ public function testRenameColumnException(): void
$table->renameColumn('baz', 'Baz');
}

public function testRenameColumnLoop(): void
{
$table = new Table('foo');
$table->addColumn('baz', Types::INTEGER);
$table->renameColumn('baz', 'foo');
self::assertCount(1, $table->getRenamedColumns());
$table->renameColumn('foo', 'baz');
self::assertCount(1, $table->getColumns());
self::assertCount(0, $table->getRenamedColumns());
}

public function testColumnsCaseInsensitive(): void
{
$table = new Table('foo');
Expand Down

0 comments on commit d27d676

Please sign in to comment.