Skip to content

Commit

Permalink
Returns null in AlterTable methods where callables do nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed May 16, 2022
1 parent 90a2035 commit 3180a5d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Definition/AlterTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions tests/Definition/AlterTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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');
Expand Down

0 comments on commit 3180a5d

Please sign in to comment.