]> git.mxchange.org Git - friendica.git/blob - tests/DatabaseTest.php
Remove default from backend columns
[friendica.git] / tests / DatabaseTest.php
1 <?php
2 /**
3  * DatabaseTest class.
4  */
5
6 namespace Friendica\Test;
7
8 use Friendica\Database\DBA;
9 use PHPUnit\DbUnit\DataSet\YamlDataSet;
10 use PHPUnit\DbUnit\TestCaseTrait;
11 use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
12
13 require_once __DIR__ . '/../boot.php';
14
15 /**
16  * Abstract class used by tests that need a database.
17  */
18 abstract class DatabaseTest extends MockedTest
19 {
20         use TestCaseTrait;
21
22         /**
23          * Get database connection.
24          *
25          * This function is executed before each test in order to get a database connection that can be used by tests.
26          * If no prior connection is available, it tries to create one using the USER, PASS and DB environment variables.
27          *
28          * If it could not connect to the database, the test is skipped.
29          *
30          * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
31          * @see https://phpunit.de/manual/5.7/en/database.html
32          */
33         protected function getConnection()
34         {
35                 if (!getenv('MYSQL_DATABASE')) {
36                         $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
37                 }
38
39                 DBA::connect(getenv('MYSQL_HOST'),
40                         getenv('MYSQL_USERNAME'),
41                         getenv('MYSQL_PASSWORD'),
42                         getenv('MYSQL_DATABASE'));
43
44                 if (!DBA::connected()) {
45                         $this->markTestSkipped('Could not connect to the database.');
46                 }
47
48                 return $this->createDefaultDBConnection(DBA::getConnection(), getenv('MYSQL_DATABASE'));
49         }
50
51         /**
52          * Get dataset to populate the database with.
53          * @return YamlDataSet
54          * @see https://phpunit.de/manual/5.7/en/database.html
55          */
56         protected function getDataSet()
57         {
58                 return new YamlDataSet(__DIR__ . '/datasets/api.yml');
59         }
60 }