From 5de8951de53632a7c9fb9cf6c9595858878bf08b Mon Sep 17 00:00:00 2001 From: Benoit Foujols Date: Fri, 29 Dec 2023 13:45:27 +0100 Subject: [PATCH] #43 fix test DatabaseServiceTest.php --- tests/ConfigCoreTest.php | 25 +++++++++++++++++++++++++ tests/Service/DatabaseServiceTest.php | 20 ++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/tests/ConfigCoreTest.php b/tests/ConfigCoreTest.php index 03d50a9..e7c9560 100644 --- a/tests/ConfigCoreTest.php +++ b/tests/ConfigCoreTest.php @@ -52,4 +52,29 @@ public function testGetEnvDbName() { $this->assertEquals('app_db', ConfigCore::getEnv('DB_NAME')); } + + public function testGetEnvDbHost() + { + $this->assertEquals('127.0.0.1', ConfigCore::getEnv('DB_HOST')); + } + + public function testGetEnvDbSocket() + { + $this->assertEquals('3306', ConfigCore::getEnv('DB_SOCKET')); + } + + public function testGetEnvDbType() + { + $this->assertEquals('postgres', ConfigCore::getEnv('DB_TYPE')); + } + + public function testGetEnvDbUser() + { + $this->assertEquals('root', ConfigCore::getEnv('DB_USER')); + } + + public function testGetEnvDbPwd() + { + $this->assertEquals('root', ConfigCore::getEnv('DB_PASSWORD')); + } } diff --git a/tests/Service/DatabaseServiceTest.php b/tests/Service/DatabaseServiceTest.php index 0a48a64..0f9d283 100644 --- a/tests/Service/DatabaseServiceTest.php +++ b/tests/Service/DatabaseServiceTest.php @@ -31,17 +31,25 @@ public function testGetConnectError() new DatabaseService(); } - public function testInstanceOfClassPdo() + public function testNoExistDriverPgsql() { - $_ENV["DB_TYPE"] = "mysql"; + $dotenv = Dotenv::createImmutable(__DIR__ . '/../Config/'); + $dotenv->load(); + (new ConfigCore([])); + $this->expectException(ErrorDatabaseNotExistException::class); new DatabaseService(); - $this->assertInstanceOf(PDO::class, DatabaseService::getConnect()); } - public function testNoExistDriverPgsql() + public function testInstanceOfPdo() { - $_ENV["DB_TYPE"] = "pgsql"; - $this->expectException(ErrorDatabaseNotExistException::class); + $dotenv = Dotenv::createImmutable(__DIR__ . '/../Config/'); + $dotenv->load(); + (new ConfigCore([])); + + $_ENV["DB_TYPE"] = "mysql"; + $_ENV["DB_PASSWORD"] = ""; + new DatabaseService(); + $this->assertInstanceOf(PDO::class, DatabaseService::getConnect()); } }