From d27d6763404914b13380d7ab60c026106153674b Mon Sep 17 00:00:00 2001 From: Tofandel Date: Tue, 29 Aug 2023 11:32:12 +0200 Subject: [PATCH] Add rename loop case --- src/Schema/Table.php | 4 +++- tests/Schema/TableTest.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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');