Files
FOSSBilling/tests-legacy/includes/BBDatabaseTestCase.php
T
Adam Daley a9b903c222 Codebase modernisation, configuration cleanup, and improved type safety (#2957)
* Refactor tests to replace depreciated functions

* Update Rector config and dependencies

* Rector: Add explicit string casting for stricter type safety

* Rector: Add return type hints to methods across codebase

* Rector: Increase dead code level and refactor invoice item logic

* Remove unnecessary `willReturn` from test mocks

Eliminate redundant `willReturn(null)` and similar calls from PHPUnit mock setups in legacy module tests, leaving only method expectations. Also update some test values to use floats for consistency.

* Refactor API controller and email adapter return values

* Update formatting and guidelines in `AGENTS.md`
2025-10-11 23:39:44 +01: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((string) $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);
}
}