Files
FOSSBilling/tests-legacy/includes/BBDatabaseTestCase.php
T
Belle Aerni 8f4d0d4cac More tests and CI improvements (#2078)
* Wrote a few more tests, improvements

* Ran Rector & PHP-CS-Fixer

* Append a capital letter to the test client passwords

* Minor tweaks

* Display more info after the tests run

* Oops, I forgot to set the dir

* Fix cron behavior for test env, dropped legacy tests

* Rename the empty test suite so PHPUnit ignores it

* Update cspell.json

* Minor tweaks to the tests

* Fixes
2024-01-17 18:11:45 -08:00

49 lines
1.2 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
abstract class BBDatabaseTestCase extends TestCase
{
private static ?PDO $pdo = null;
private $conn;
protected $_seedFilesPath;
protected $_initialSeedFile = 'initial.xml';
final public function getConnection()
{
if ($this->conn === null) {
if (self::$pdo == null) {
self::$pdo = new PDO('mysql:dbname=' . BB_DB_NAME . ';host=127.0.0.1;port=' . BB_DB_PORT, BB_DB_USER, BB_DB_PASSWORD);
}
$this->conn = $this->createDefaultDBConnection(self::$pdo, BB_DB_NAME);
}
return $this->conn;
}
/**
* Returns the seed files folder path.
*
* @return string
*/
public function getSeedFilesPath()
{
if ($this->_seedFilesPath == null) {
$this->_seedFilesPath = PATH_TESTS . '/fixtures';
}
return rtrim($this->_seedFilesPath, '/') . '/';
}
/**
* Retrieve from flat XML files data used to populate the database.
*
* @return PHPUnit_Extensions_Database_DataSet_IDataSet
*/
protected function getDataSet()
{
return $this->createFlatXmlDataSet($this->getSeedFilesPath() . $this->_initialSeedFile);
}
}