bindAPI/tests/Unit/Controller/DatabaseConnectionTest.php

43 lines
1.3 KiB
PHP
Raw Normal View History

2022-10-07 11:33:08 +02:00
<?php
namespace Unit\Controller;
use App\Controller\ConfigController;
use App\Controller\DatabaseConnection;
use PDO;
use PDOException;
/**
* @covers \App\Controller\DatabaseConnection
* @covers \App\Controller\ConfigController
*/
2022-10-08 10:45:54 +02:00
class DatabaseConnectionTest extends BindApiControllerTest
2022-10-07 11:33:08 +02:00
{
private PDO $dbConnection;
public function testGetConnection()
{
2022-10-08 10:45:54 +02:00
$configController = new ConfigController(test: true);
2022-10-07 11:33:08 +02:00
$dbHost = $configController->getConfig(configKey: 'dbHost');
$dbPort = $configController->getConfig(configKey: 'dbPort');
$dbDatabase = $configController->getConfig(configKey: 'dbDatabase');
$dbUser = $configController->getConfig(configKey: 'dbUser');
$dbPassword = $configController->getConfig(configKey: 'dbPassword');
try {
$this->dbConnection = new PDO(
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",
username: $dbUser,
password: $dbPassword
);
} catch (PDOException $e) {
$this->fail(message: $e->getMessage());
}
$databaseConnection = new DatabaseConnection(configController: $configController);
self::assertEquals(expected: $databaseConnection->getConnection(), actual: $this->dbConnection);
}
}