]> git.mxchange.org Git - friendica.git/blob - tests/DatabaseTest.php
Fixed E_NOTICE when no 'term' was provided (#5391)
[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          *
26          * This function is executed before each test in order to get a database connection that can be used by tests.
27          * If no prior connection is available, it tries to create one using the USER, PASS and DB environment variables.
28          *
29          * If it could not connect to the database, the test is skipped.
30          *
31          * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
32          * @see https://phpunit.de/manual/5.7/en/database.html
33          */
34         protected function getConnection()
35         {
36                 if (!dba::connected()) {
37                         $this->markTestSkipped('Could not connect to the database.');
38                 }
39
40                 return $this->createDefaultDBConnection(dba::get_db(), getenv('MYSQL_DATABASE'));
41         }
42
43         /**
44          * Get dataset to populate the database with.
45          * @return YamlDataSet
46          * @see https://phpunit.de/manual/5.7/en/database.html
47          */
48         protected function getDataSet()
49         {
50                 return new YamlDataSet(__DIR__ . '/datasets/api.yml');
51         }
52 }