]> git.mxchange.org Git - friendica.git/blob - tests/DatabaseTest.php
7819b46ab8f2178b57c285be16992be5151f9c49
[friendica.git] / tests / DatabaseTest.php
1 <?php
2 /**
3  * DatabaseTest class.
4  */
5
6 namespace Friendica\Test;
7
8 use dba;
9 use Friendica\Database\DBStructure;
10 use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
11 use PHPUnit\DbUnit\DataSet\YamlDataSet;
12 use PHPUnit\DbUnit\TestCaseTrait;
13 use PHPUnit\Framework\TestCase;
14
15 /**
16  * Abstract class used by tests that need a database.
17  */
18 abstract class DatabaseTest extends TestCase
19 {
20
21         use TestCaseTrait;
22
23         /**
24          * Get database connection.
25          * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
26          * @see https://phpunit.de/manual/5.7/en/database.html
27          */
28         protected function getConnection()
29         {
30                 if (!dba::$connected) {
31                         dba::connect('localhost', getenv('USER'), getenv('PASS'), getenv('DB'));
32
33                         if (dba::$connected) {
34                                 $app = get_app();
35                                 // We need to do this in order to disable logging
36                                 $app->module = 'install';
37
38                                 // Create database structure
39                                 DBStructure::update(false, true, true);
40                         } else {
41                                 $this->markTestSkipped('Could not connect to the database.');
42                         }
43                 }
44
45                 return $this->createDefaultDBConnection(dba::get_db(), 'friendica_test:');
46         }
47
48         /**
49          * Get dataset to populate the database with.
50          * @return YamlDataSet
51          * @see https://phpunit.de/manual/5.7/en/database.html
52          */
53         protected function getDataSet()
54         {
55                 return new YamlDataSet(__DIR__ . '/datasets/api.yml');
56         }
57 }