]> git.mxchange.org Git - friendica.git/blobdiff - tests/DatabaseTest.php
Fixing installer
[friendica.git] / tests / DatabaseTest.php
index bb87cf36dc8bced6a633d58ba2dbf851975ccfd1..5f9d3bf72cdc05b835e18443463f01c5bc49a296 100644 (file)
@@ -5,14 +5,17 @@
 
 namespace Friendica\Test;
 
-use Friendica\Core\Config\Cache;
-use Friendica\Database\DBA;
-use Friendica\Factory;
+use Friendica\App\Mode;
+use Friendica\Core\Config\Cache\ConfigCache;
+use Friendica\Database\Database;
+use Friendica\Factory\ConfigFactory;
 use Friendica\Util\BasePath;
+use Friendica\Util\ConfigFileLoader;
 use Friendica\Util\Profiler;
 use PHPUnit\DbUnit\DataSet\YamlDataSet;
 use PHPUnit\DbUnit\TestCaseTrait;
 use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
+use Psr\Log\NullLogger;
 
 require_once __DIR__ . '/../boot.php';
 
@@ -23,6 +26,34 @@ abstract class DatabaseTest extends MockedTest
 {
        use TestCaseTrait;
 
+       /** @var Database */
+       protected static $dba;
+
+       /** @var BasePath */
+       protected static $basePath;
+
+       /** @var Mode */
+       protected static $mode;
+
+       /** @var ConfigCache */
+       protected static $configCache;
+
+       /** @var Profiler */
+       protected static $profiler;
+
+       public static function setUpBeforeClass()
+       {
+               parent::setUpBeforeClass();
+
+               self::$basePath = new BasePath(dirname(__DIR__));
+               $configLoader = new ConfigFileLoader(self::$basePath->getPath());
+               $configFactory = new ConfigFactory();
+               self::$configCache = $configFactory->createCache($configLoader);
+               self::$profiler = new Profiler(self::$configCache);
+               self::$dba = new Database(self::$configCache, self::$profiler, new NullLogger(), $_SERVER);
+               self::$mode = new Mode(self::$basePath, self::$dba, self::$configCache);
+       }
+
        /**
         * Get database connection.
         *
@@ -40,26 +71,13 @@ abstract class DatabaseTest extends MockedTest
                        $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
                }
 
-               $basedir = BasePath::create(dirname(__DIR__));
-               $configLoader = new Cache\ConfigCacheLoader($basedir);
-               $config = Factory\ConfigFactory::createCache($configLoader);
-
-               $profiler = \Mockery::mock(Profiler::class);
-
-               DBA::connect(
-                       $basedir,
-                       $config,
-                       $profiler,
-                       getenv('MYSQL_HOST'),
-                       getenv('MYSQL_USERNAME'),
-                       getenv('MYSQL_PASSWORD'),
-                       getenv('MYSQL_DATABASE'));
-
-               if (!DBA::connected()) {
-                       $this->markTestSkipped('Could not connect to the database.');
+               if (!self::$dba->isConnected()) {
+                       if (!self::$dba->connect()) {
+                               $this->markTestSkipped('Could not connect to the database.');
+                       }
                }
 
-               return $this->createDefaultDBConnection(DBA::getConnection(), getenv('MYSQL_DATABASE'));
+               return $this->createDefaultDBConnection(self::$dba->getConnection(), getenv('MYSQL_DATABASE'));
        }
 
        /**