initial commit
This commit is contained in:
parent
d2f733d8c2
commit
c1a54aa23e
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Unit\Controller;
|
||||||
|
|
||||||
|
use App\Controller\ConfigController;
|
||||||
|
use App\Controller\DatabaseConnection;
|
||||||
|
use PDO;
|
||||||
|
use PDOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \App\Controller\DatabaseConnection
|
||||||
|
* @covers \App\Controller\ConfigController
|
||||||
|
*/
|
||||||
|
class DatabaseConnectionTest extends BindApiTestController
|
||||||
|
{
|
||||||
|
private PDO $dbConnection;
|
||||||
|
|
||||||
|
public function testGetConnection()
|
||||||
|
{
|
||||||
|
|
||||||
|
$configController = new ConfigController(test: true);
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue