namespace Friendica\Test;
-use Friendica\Core\Config;
-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';
{
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.
*
$this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
}
- $basedir = BasePath::create(dirname(__DIR__));
- $configLoader = new Config\ConfigCacheLoader($basedir);
- $config = Factory\ConfigFactory::createCache($configLoader);
-
- DBA::connect(
- $config,
- 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'));
}
/**