Skip to content

Commit

Permalink
fix #1732 BcDatabaseService::addColumn のユニットテストを実装 (#1796)
Browse files Browse the repository at this point in the history
  • Loading branch information
mb-t-goto committed Feb 6, 2023
1 parent 8e679d5 commit 3ded09d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions plugins/baser-core/src/Service/BcDatabaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public function getMigrationsTable(string $tableName)
* @param string $type
* @param array $options
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function addColumn(
string $tableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,29 @@ public function test_getMigrationsTable()
*/
public function test_addColumn()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
// テーブル生成
$table = 'table_test_add';
$columns = [
'id' => ['type' => 'integer'],
'contents' => ['type' => 'text'],
];
$schema = new BcSchema($table, $columns);
$schema->create();

// 対象メソッドを呼ぶ
$result = $this->BcDatabaseService->addColumn($table, 'new_column', 'integer');
$tableTest = TableRegistry::getTableLocator()
->get('BaserCore.App')
->getConnection()
->getSchemaCollection()
->describe($table);
// 戻り値を確認
$this->assertTrue($result);
// 新しいカラムが生成されたか確認
$this->assertTrue($tableTest->hasColumn('new_column'));

// テストテーブルを削除
$this->BcDatabaseService->dropTable($table);
}

/**
Expand Down

0 comments on commit 3ded09d

Please sign in to comment.