Skip to content

Commit 5ab61e3

Browse files
authored
fix #1733 BcDatabaseService::removeColumn のユニットテストを実装 (#1797)
1 parent 3ded09d commit 5ab61e3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

plugins/baser-core/src/Service/BcDatabaseService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ public function addColumn(
149149
* @param string $tableName
150150
* @param string $columnName
151151
* @return bool
152+
* @checked
153+
* @noTodo
154+
* @unitTest
152155
*/
153156
public function removeColumn(string $tableName, string $columnName)
154157
{

plugins/baser-core/tests/TestCase/Service/BcDatabaseServiceTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,29 @@ public function test_addColumn()
139139
*/
140140
public function test_removeColumn()
141141
{
142-
$this->markTestIncomplete('このテストは、まだ実装されていません。');
142+
// テーブル生成
143+
$table = 'table_test_remove';
144+
$columns = [
145+
'id' => ['type' => 'integer'],
146+
'remove_column' => ['type' => 'text'],
147+
];
148+
$schema = new BcSchema($table, $columns);
149+
$schema->create();
150+
151+
// 対象メソッドを呼ぶ
152+
$result = $this->BcDatabaseService->removeColumn($table, 'remove_column');
153+
$tableTest = TableRegistry::getTableLocator()
154+
->get('BaserCore.App')
155+
->getConnection()
156+
->getSchemaCollection()
157+
->describe($table);
158+
// 戻り値を確認
159+
$this->assertTrue($result);
160+
// カラムが削除されているか確認
161+
$this->assertFalse($tableTest->hasColumn('remove_column'));
162+
163+
// テストテーブルを削除
164+
$this->BcDatabaseService->dropTable($table);
143165
}
144166

145167
/**

0 commit comments

Comments
 (0)