X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2FDatabaseTest.php;h=03bebb7b54b4f69c09c45f74867cc5e9213359f0;hb=f23ecaff6af1982112469f90d6bcdf0408b0f22e;hp=3ff4c6fe14f529aa00066dc466092ea883e42fe8;hpb=5f17ce574fa37e84592d1dc1518ae34d58654b6f;p=friendica.git diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 3ff4c6fe14..03bebb7b54 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -1,74 +1,44 @@ . + * */ namespace Friendica\Test; -use Friendica\Core\Config\Cache; -use Friendica\Database\DBA; -use Friendica\Factory; -use Friendica\Util\BasePath; -use Friendica\Util\Profiler; -use PHPUnit\DbUnit\DataSet\YamlDataSet; -use PHPUnit\DbUnit\TestCaseTrait; -use PHPUnit_Extensions_Database_DB_IDatabaseConnection; - -require_once __DIR__ . '/../boot.php'; - /** * Abstract class used by tests that need a database. */ abstract class DatabaseTest extends MockedTest { - use TestCaseTrait; + use DatabaseTestTrait; - /** - * 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() + protected function setUp(): void { - if (!getenv('MYSQL_DATABASE')) { - $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.'); - } - - $basePath = BasePath::create(dirname(__DIR__)); - $configLoader = new Cache\ConfigCacheLoader($basePath); - $config = Factory\ConfigFactory::createCache($configLoader); - - $profiler = \Mockery::mock(Profiler::class); + $this->setUpDb(); - 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::getConnection(), getenv('MYSQL_DATABASE')); + parent::setUp(); } - /** - * Get dataset to populate the database with. - * @return YamlDataSet - * @see https://phpunit.de/manual/5.7/en/database.html - */ - protected function getDataSet() + protected function tearDown(): void { - return new YamlDataSet(__DIR__ . '/datasets/api.yml'); + $this->tearDownDb(); + + parent::tearDown(); } }