Skip to content

Commit

Permalink
Merge pull request #3929 from HungDV2022/unitest_InstallationsService…
Browse files Browse the repository at this point in the history
…_testConnectDb

InstallationsService::testConnectDb() のユニットテスト
  • Loading branch information
HungDV2022 authored Oct 24, 2024
2 parents fafdf03 + 62746fd commit 6f5cae9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/bc-installer/src/Service/InstallationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public function getRealDbName(string $type, string $name)
* @throws BcException
* @checked
* @noTodo
* @unitTest
*/
public function testConnectDb(array $config)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,30 @@ public static function getRealDbNameDataProvider()
*/
public function testTestConnectDb()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->loadPlugins(['BcInstaller']);
// 接続情報を設定 MYSQL
$config = [
"datasource" => "MySQL",
"database" => "test_basercms",
"host" => "bc-db",
"port" => "3306",
"username" => "root",
"password" => "root",
"schema" => "",
"prefix" => "",
"encoding" => "utf8"
];
//接続できる場合、エラを返さない
$this->Installations->testConnectDb($config);

// 接続できない場合、エラーを返す
$config['host'] = 'test';
$this->expectException("PDOException");
$this->expectExceptionMessage('データベースへの接続でエラーが発生しました。データベース設定を見直してください。
サーバー上に指定されたデータベースが存在しない可能性が高いです。
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for test failed: ');

$this->Installations->testConnectDb($config);
}

/**
Expand Down

0 comments on commit 6f5cae9

Please sign in to comment.