X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2FDatabaseTest.php;h=2cb76dcad9ab39a013987026d6c4248bbe2afa56;hb=a3c1beb265ec91a504ac4ee2ba1343122e6c66ae;hp=7819b46ab8f2178b57c285be16992be5151f9c49;hpb=f7064be41f23a347da7b54fd8c19b99036f128ae;p=friendica.git diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 7819b46ab8..2cb76dcad9 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -5,44 +5,47 @@ namespace Friendica\Test; -use dba; -use Friendica\Database\DBStructure; -use PHPUnit_Extensions_Database_DB_IDatabaseConnection; +use Friendica\Database\DBA; 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; /** * Get database connection. + * + * This function is executed before each test in order to get a database connection that can be used by tests. + * If no prior connection is available, it tries to create one using the USER, PASS and DB environment variables. + * + * If it could not connect to the database, the test is skipped. + * * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection * @see https://phpunit.de/manual/5.7/en/database.html */ protected function getConnection() { - if (!dba::$connected) { - dba::connect('localhost', getenv('USER'), getenv('PASS'), getenv('DB')); - - if (dba::$connected) { - $app = get_app(); - // We need to do this in order to disable logging - $app->module = 'install'; - - // Create database structure - DBStructure::update(false, true, true); - } else { - $this->markTestSkipped('Could not connect to the database.'); - } + if (!getenv('MYSQL_DATABASE')) { + $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.'); + } + + DBA::connect(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(), 'friendica_test:'); + return $this->createDefaultDBConnection(DBA::getConnection(), getenv('MYSQL_DATABASE')); } /**