diff --git a/src/Schema/Table.php b/src/Schema/Table.php index abb2af8eadf..c056cc06ec4 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -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; } diff --git a/tests/Schema/TableTest.php b/tests/Schema/TableTest.php index d72eaa72cad..f6fb4da8a7d 100644 --- a/tests/Schema/TableTest.php +++ b/tests/Schema/TableTest.php @@ -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');