X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2FDatabaseTest.php;h=fec31b05af6f69aa49deee5c16a9c957a445b5c7;hb=e0b1f4f2519c6a5e02f98423f34648f21aa5c879;hp=579e45084d5617277b5f71fa367bf36b025534b7;hpb=2fa6cc000013089d59d9cc221b544ed1a7a4cd37;p=friendica.git diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 579e45084d..fec31b05af 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -5,19 +5,23 @@ namespace Friendica\Test; -use dba; -use Friendica\Database\DBStructure; -use PHPUnit_Extensions_Database_DB_IDatabaseConnection; +use Friendica\App; +use Friendica\Database\DBA; +use Friendica\Factory; +use Friendica\Util\BasePath; +use Friendica\Util\Config\ConfigFileLoader; +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; /** @@ -33,11 +37,31 @@ abstract class DatabaseTest extends TestCase */ protected function getConnection() { - if (!dba::connected()) { + 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( + $basePath, + $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.'); } - return $this->createDefaultDBConnection(dba::get_db(), getenv('MYSQL_DATABASE')); + return $this->createDefaultDBConnection(DBA::getConnection(), getenv('MYSQL_DATABASE')); } /**