Skip to content

Commit

Permalink
#43 fix test DatabaseServiceTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bfoujols committed Dec 29, 2023
1 parent ad0273a commit 5de8951
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
25 changes: 25 additions & 0 deletions tests/ConfigCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
20 changes: 14 additions & 6 deletions tests/Service/DatabaseServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 5de8951

Please sign in to comment.