. */ namespace SP\Tests; use PHPUnit\DbUnit\Database\DefaultConnection; use PHPUnit\DbUnit\DataSet\IDataSet; use PHPUnit\DbUnit\TestCaseTrait; use PHPUnit\Framework\TestCase; use SP\Storage\Database\DatabaseConnectionData; /** * Class DatabaseBaseTest * * Caso de test para tests que requieran consultas a la BBDD * * @package SP\Tests */ abstract class DatabaseTestCase extends TestCase { use TestCaseTrait; /** * @var DatabaseConnectionData */ protected static $databaseConnectionData; /** * @var string */ protected static $dataset = 'syspass.xml'; /** * @var \PDO */ private static $pdo; /** * @var DefaultConnection */ protected $conn; /** * Returns the test database connection. * * @return DefaultConnection * @throws \SP\Core\Exceptions\SPException */ final public function getConnection() { if ($this->conn === null) { if (self::$pdo === null) { self::$pdo = getDbHandler()->getConnection(); } $this->conn = $this->createDefaultDBConnection(self::$pdo, 'syspass'); } return $this->conn; } /** * Returns the test dataset. * * @return IDataSet */ protected function getDataSet() { return $this->createMySQLXMLDataSet(RESOURCE_DIR . DIRECTORY_SEPARATOR . 'datasets' . DIRECTORY_SEPARATOR . self::$dataset); } }