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