Skip to content

Commit ec2273d

Browse files
authored
Added methods whenTableHasColumn and whenTableDoesntHaveColumn to \Hyperf\Database\Schema\Schema (#7024)
1 parent c4515bd commit ec2273d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/Cases/SchemaBuilderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ public function testView(): void
8181
Schema::drop('view_1');
8282
}
8383

84+
public function testWhenTableHasColumn(): void
85+
{
86+
Schema::create('foo', static function (Blueprint $table) {
87+
$table->comment('This is a comment');
88+
$table->increments('id');
89+
});
90+
Schema::whenTableDoesntHaveColumn('foo', 'name', static function (Blueprint $table) {
91+
$table->string('name');
92+
});
93+
$this->assertTrue(Schema::hasColumn('foo', 'name'));
94+
Schema::whenTableHasColumn('foo', 'name', static function (Blueprint $table) {
95+
$table->dropColumn('name');
96+
});
97+
$this->assertFalse(Schema::hasColumn('foo', 'name'));
98+
Schema::drop('foo');
99+
}
100+
84101
public function testColumn(): void
85102
{
86103
Schema::create('column_1', static function (Blueprint $table) {

0 commit comments

Comments
 (0)