3 namespace Friendica\Test\src\Core\Lock;
6 use Friendica\Core\Lock\DatabaseLockDriver;
7 use Friendica\Database\DBStructure;
8 use PHPUnit\DbUnit\DataSet\YamlDataSet;
9 use PHPUnit\DbUnit\TestCaseTrait;
10 use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
12 class DatabaseLockDriverTest extends LockTest
17 * Get database connection.
19 * This function is executed before each test in order to get a database connection that can be used by tests.
20 * If no prior connection is available, it tries to create one using the USER, PASS and DB environment variables.
22 * If it could not connect to the database, the test is skipped.
24 * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
25 * @see https://phpunit.de/manual/5.7/en/database.html
27 protected function getConnection()
29 if (!dba::$connected) {
30 dba::connect('localhost', getenv('USER'), getenv('PASS'), getenv('DB'));
32 if (dba::$connected) {
34 // We need to do this in order to disable logging
35 $app->module = 'install';
37 // Create database structure
38 DBStructure::update(false, true, true);
40 $this->markTestSkipped('Could not connect to the database.');
44 return $this->createDefaultDBConnection(dba::get_db(), getenv('DB'));
48 * Get dataset to populate the database with.
50 * @see https://phpunit.de/manual/5.7/en/database.html
52 protected function getDataSet()
54 return new YamlDataSet(__DIR__ . '/../../../datasets/api.yml');
57 protected function getInstance()
59 return new DatabaseLockDriver();
62 public function tearDown()
64 dba::delete('locks', [ 'id > 0']);