From 3180a5de7fc4ac77f0b10bd6d94fefdc23a82004 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Mon, 16 May 2022 18:16:40 -0300 Subject: [PATCH] Returns null in AlterTable methods where callables do nothing --- src/Definition/AlterTable.php | 6 +++--- tests/Definition/AlterTableTest.php | 33 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Definition/AlterTable.php b/src/Definition/AlterTable.php index 8cc67db..dfeef32 100644 --- a/src/Definition/AlterTable.php +++ b/src/Definition/AlterTable.php @@ -186,7 +186,7 @@ protected function renderAdd() : ?string } $definition = new TableDefinition($this->database); $this->sql['add']($definition); - return $definition->sql('ADD'); + return $definition->sql('ADD') ?: null; } /** @@ -207,7 +207,7 @@ protected function renderChange() : ?string } $definition = new TableDefinition($this->database); $this->sql['change']($definition); - return $definition->sql('CHANGE'); + return $definition->sql('CHANGE') ?: null; } /** @@ -228,7 +228,7 @@ protected function renderModify() : ?string } $definition = new TableDefinition($this->database); $this->sql['modify']($definition); - return $definition->sql('MODIFY'); + return $definition->sql('MODIFY') ?: null; } public function dropColumn(string $name, bool $ifExists = false) : static diff --git a/tests/Definition/AlterTableTest.php b/tests/Definition/AlterTableTest.php index 1aece43..5e6d292 100644 --- a/tests/Definition/AlterTableTest.php +++ b/tests/Definition/AlterTableTest.php @@ -67,6 +67,17 @@ public function testAdd() : void ); } + public function testAddEmpty() : void + { + $sql = $this->alterTable->table('t1') + ->add(static function (TableDefinition $definition) : void { + }); + self::assertSame( + "ALTER TABLE `t1`\n", + $sql->sql() + ); + } + public function testChange() : void { $sql = $this->alterTable->table('t1') @@ -79,6 +90,17 @@ public function testChange() : void ); } + public function testChangeEmpty() : void + { + $sql = $this->alterTable->table('t1') + ->change(static function (TableDefinition $definition) : void { + }); + self::assertSame( + "ALTER TABLE `t1`\n", + $sql->sql() + ); + } + public function testModify() : void { $sql = $this->alterTable->table('t1') @@ -91,6 +113,17 @@ public function testModify() : void ); } + public function testModifyEmpty() : void + { + $sql = $this->alterTable->table('t1') + ->modify(static function (TableDefinition $definition) : void { + }); + self::assertSame( + "ALTER TABLE `t1`\n", + $sql->sql() + ); + } + public function testDropColumnIfExists() : void { $alterTable = $this->alterTable->table('t1')->dropColumnIfExists('foo');