]> git.mxchange.org Git - friendica.git/blobdiff - tests/DatabaseTest.php
Add themed themed error page or login page for /admin[/*]
[friendica.git] / tests / DatabaseTest.php
index 88cc2d84bac1f43371e440e243bfb096e4662745..b3418c20f4024878c9999ebf9f6d908d6374335b 100644 (file)
@@ -5,18 +5,24 @@
 
 namespace Friendica\Test;
 
+use Friendica\App;
 use Friendica\Database\DBA;
+use Friendica\Factory;
+use Friendica\Util\BasePath;
+use Friendica\Util\Config\ConfigFileLoader;
+use Friendica\Util\Logger\VoidLogger;
+use Friendica\Util\Profiler;
 use PHPUnit\DbUnit\DataSet\YamlDataSet;
 use PHPUnit\DbUnit\TestCaseTrait;
-use PHPUnit\Framework\TestCase;
 use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
 
+require_once __DIR__ . '/../boot.php';
+
 /**
  * Abstract class used by tests that need a database.
  */
-abstract class DatabaseTest extends TestCase
+abstract class DatabaseTest extends MockedTest
 {
-
        use TestCaseTrait;
 
        /**
@@ -32,6 +38,26 @@ abstract class DatabaseTest extends TestCase
         */
        protected function getConnection()
        {
+               if (!getenv('MYSQL_DATABASE')) {
+                       $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
+               }
+
+               $basePath = BasePath::create(dirname(__DIR__));
+               $mode = new App\Mode($basePath);
+               $configLoader = new ConfigFileLoader($basePath, $mode);
+               $config = Factory\ConfigFactory::createCache($configLoader);
+
+               $profiler = \Mockery::mock(Profiler::class);
+
+               DBA::connect(
+                       $config,
+                       $profiler,
+                       new VoidLogger(),
+                       getenv('MYSQL_HOST'),
+                       getenv('MYSQL_USERNAME'),
+                       getenv('MYSQL_PASSWORD'),
+                       getenv('MYSQL_DATABASE'));
+
                if (!DBA::connected()) {
                        $this->markTestSkipped('Could not connect to the database.');
                }