ulogger-server/.tests/lib/UloggerDatabaseTestCase.php

44 lines
1.0 KiB
PHP
Raw Normal View History

2017-09-05 09:36:10 +02:00
<?php
require_once("BaseDatabaseTestCase.php");
require_once(__DIR__ . "/../../helpers/db.php");
class UloggerDatabaseTestCase extends BaseDatabaseTestCase {
2019-05-15 12:03:55 +02:00
/**
* @var uDb $udb
*/
2017-09-05 09:36:10 +02:00
static private $udb = null;
2020-05-20 17:12:07 +02:00
/**
* @throws ReflectionException
*/
2021-04-22 19:47:52 +02:00
public static function setUpBeforeClass(): void {
2017-09-05 09:36:10 +02:00
parent::setUpBeforeClass();
if (file_exists(__DIR__ . '/../.env')) {
2021-04-22 21:44:03 +02:00
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__ . '/..');
2017-09-05 09:36:10 +02:00
$dotenv->load();
2019-01-24 19:07:41 +01:00
$dotenv->required(['DB_DSN', 'DB_USER', 'DB_PASS']);
2017-09-05 09:36:10 +02:00
}
2021-04-22 21:44:03 +02:00
$db_dsn = getenv('DB_DSN');
$db_user = getenv('DB_USER');
$db_pass = getenv('DB_PASS');
2017-09-05 09:36:10 +02:00
// uDb connection
if (self::$udb == null) {
2021-04-22 19:47:52 +02:00
self::$udb = new ReflectionClass('uDb');
2017-09-05 09:36:10 +02:00
$dbInstance = self::$udb->getProperty('instance');
$dbInstance->setAccessible(true);
2019-01-24 19:07:41 +01:00
$dbInstance->setValue(new uDb($db_dsn, $db_user, $db_pass));
2017-09-05 09:36:10 +02:00
}
}
2021-04-22 19:47:52 +02:00
public static function tearDownAfterClass(): void {
2017-09-05 09:36:10 +02:00
parent::tearDownAfterClass();
self::$udb = null;
}
}
?>