Skip to content

Commit 3ded09d

Browse files
authored
fix #1732 BcDatabaseService::addColumn のユニットテストを実装 (#1796)
1 parent 8e679d5 commit 3ded09d

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
@@ -121,6 +121,9 @@ public function getMigrationsTable(string $tableName)
121121
* @param string $type
122122
* @param array $options
123123
* @return bool
124+
* @checked
125+
* @noTodo
126+
* @unitTest
124127
*/
125128
public function addColumn(
126129
string $tableName,

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,29 @@ public function test_getMigrationsTable()
109109
*/
110110
public function test_addColumn()
111111
{
112-
$this->markTestIncomplete('このテストは、まだ実装されていません。');
112+
// テーブル生成
113+
$table = 'table_test_add';
114+
$columns = [
115+
'id' => ['type' => 'integer'],
116+
'contents' => ['type' => 'text'],
117+
];
118+
$schema = new BcSchema($table, $columns);
119+
$schema->create();
120+
121+
// 対象メソッドを呼ぶ
122+
$result = $this->BcDatabaseService->addColumn($table, 'new_column', 'integer');
123+
$tableTest = TableRegistry::getTableLocator()
124+
->get('BaserCore.App')
125+
->getConnection()
126+
->getSchemaCollection()
127+
->describe($table);
128+
// 戻り値を確認
129+
$this->assertTrue($result);
130+
// 新しいカラムが生成されたか確認
131+
$this->assertTrue($tableTest->hasColumn('new_column'));
132+
133+
// テストテーブルを削除
134+
$this->BcDatabaseService->dropTable($table);
113135
}
114136

115137
/**

0 commit comments

Comments
 (0)