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