]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Lock/DatabaseLockDriverTest.php
a80ff4c37cef4dbff7c6c50f5a112b26497dca89
[friendica.git] / tests / src / Core / Lock / DatabaseLockDriverTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Lock;
4
5 use dba;
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;
11
12 class DatabaseLockDriverTest extends LockTest
13 {
14         use TestCaseTrait;
15
16         /**
17          * Get database connection.
18          *
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.
21          *
22          * If it could not connect to the database, the test is skipped.
23          *
24          * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
25          * @see https://phpunit.de/manual/5.7/en/database.html
26          */
27         protected function getConnection()
28         {
29                 if (!dba::$connected) {
30                         dba::connect('localhost', getenv('USER'), getenv('PASS'), getenv('DB'));
31
32                         if (dba::$connected) {
33                                 $app = get_app();
34                                 // We need to do this in order to disable logging
35                                 $app->module = 'install';
36
37                                 // Create database structure
38                                 DBStructure::update(false, true, true);
39                         } else {
40                                 $this->markTestSkipped('Could not connect to the database.');
41                         }
42                 }
43
44                 return $this->createDefaultDBConnection(dba::get_db(), getenv('DB'));
45         }
46
47         /**
48          * Get dataset to populate the database with.
49          * @return YamlDataSet
50          * @see https://phpunit.de/manual/5.7/en/database.html
51          */
52         protected function getDataSet()
53         {
54                 return new YamlDataSet(__DIR__ . '/../../../datasets/api.yml');
55         }
56
57         protected function getInstance()
58         {
59                 return new DatabaseLockDriver();
60         }
61
62         public function tearDown()
63         {
64                 dba::delete('locks', [ 'id > 0']);
65                 parent::tearDown();
66         }
67 }