Skip to content

Commit 3180a5d

Browse files
committed
Returns null in AlterTable methods where callables do nothing
1 parent 90a2035 commit 3180a5d

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

src/Definition/AlterTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected function renderAdd() : ?string
186186
}
187187
$definition = new TableDefinition($this->database);
188188
$this->sql['add']($definition);
189-
return $definition->sql('ADD');
189+
return $definition->sql('ADD') ?: null;
190190
}
191191

192192
/**
@@ -207,7 +207,7 @@ protected function renderChange() : ?string
207207
}
208208
$definition = new TableDefinition($this->database);
209209
$this->sql['change']($definition);
210-
return $definition->sql('CHANGE');
210+
return $definition->sql('CHANGE') ?: null;
211211
}
212212

213213
/**
@@ -228,7 +228,7 @@ protected function renderModify() : ?string
228228
}
229229
$definition = new TableDefinition($this->database);
230230
$this->sql['modify']($definition);
231-
return $definition->sql('MODIFY');
231+
return $definition->sql('MODIFY') ?: null;
232232
}
233233

234234
public function dropColumn(string $name, bool $ifExists = false) : static

tests/Definition/AlterTableTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ public function testAdd() : void
6767
);
6868
}
6969

70+
public function testAddEmpty() : void
71+
{
72+
$sql = $this->alterTable->table('t1')
73+
->add(static function (TableDefinition $definition) : void {
74+
});
75+
self::assertSame(
76+
"ALTER TABLE `t1`\n",
77+
$sql->sql()
78+
);
79+
}
80+
7081
public function testChange() : void
7182
{
7283
$sql = $this->alterTable->table('t1')
@@ -79,6 +90,17 @@ public function testChange() : void
7990
);
8091
}
8192

93+
public function testChangeEmpty() : void
94+
{
95+
$sql = $this->alterTable->table('t1')
96+
->change(static function (TableDefinition $definition) : void {
97+
});
98+
self::assertSame(
99+
"ALTER TABLE `t1`\n",
100+
$sql->sql()
101+
);
102+
}
103+
82104
public function testModify() : void
83105
{
84106
$sql = $this->alterTable->table('t1')
@@ -91,6 +113,17 @@ public function testModify() : void
91113
);
92114
}
93115

116+
public function testModifyEmpty() : void
117+
{
118+
$sql = $this->alterTable->table('t1')
119+
->modify(static function (TableDefinition $definition) : void {
120+
});
121+
self::assertSame(
122+
"ALTER TABLE `t1`\n",
123+
$sql->sql()
124+
);
125+
}
126+
94127
public function testDropColumnIfExists() : void
95128
{
96129
$alterTable = $this->alterTable->table('t1')->dropColumnIfExists('foo');

0 commit comments

Comments
 (0)