Compare commits

..

5 Commits

Author SHA1 Message Date
tracer 4199faecb4 initial commit 2022-10-07 19:16:26 +02:00
tracer 059e3934f9 adapted namespace 2022-10-07 12:56:28 +02:00
tracer f45dd8fbc1 moved namespace 2022-10-07 11:33:54 +02:00
tracer c1a54aa23e initial commit 2022-10-07 11:33:08 +02:00
tracer d2f733d8c2 added test support 2022-10-06 16:21:11 +02:00
5 changed files with 154 additions and 95 deletions

11
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,11 @@
pipeline {
agent any
stages {
stage('Do nothing') {
steps {
sh '/bin/true'
}
}
}
}

View File

@ -30,10 +30,12 @@ class DatabaseConnection
$dbUser = $this->configController->getConfig(configKey: 'dbUser'); $dbUser = $this->configController->getConfig(configKey: 'dbUser');
$dbPassword = $this->configController->getConfig(configKey: 'dbPassword'); $dbPassword = $this->configController->getConfig(configKey: 'dbPassword');
if (!$this->configController->getConfig(configKey: 'test')) {
// TODO create config => encryption key // TODO create config => encryption key
try { try {
$this->dbConnection = new PDO( $this->dbConnection = new PDO(
dsn : "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase", dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",
username: $dbUser, username: $dbUser,
password: $dbPassword password: $dbPassword
); );
@ -121,6 +123,7 @@ class DatabaseConnection
exit(1); exit(1);
} }
} }
}
/** /**
@ -136,7 +139,7 @@ class DatabaseConnection
} }
/** /**
* @return \PDO * @return PDO
*/ */
public function getConnection(): PDO public function getConnection(): PDO
{ {

View File

@ -1,10 +1,12 @@
<?php <?php
namespace App\Controller; namespace Unit\Controller;
use App\Controller\DatabaseConnection;
use App\Repository\NameserverRepository; use App\Repository\NameserverRepository;
use DI\Container; use DI\Container;
use DI\ContainerBuilder; use DI\ContainerBuilder;
use Exception;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use function DI\autowire; use function DI\autowire;
@ -19,7 +21,7 @@ class BindApiTestController extends TestCase
/** /**
* @param int|string $dataName * @param int|string $dataName
* *
* @throws \Exception * @throws Exception
* @internal This method is not covered by the backward compatibility promise for PHPUnit * @internal This method is not covered by the backward compatibility promise for PHPUnit
*/ */
public function __construct(?string $name = null, array $data = [], $dataName = '') public function __construct(?string $name = null, array $data = [], $dataName = '')

View File

@ -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);
}
}

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Controller; namespace Unit\Controller;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;