From 854706b812fab2bd0cb821c671e00e227c3c0c4b Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Sat, 20 Feb 2021 21:22:29 +0100 Subject: [PATCH] Fix DatabaseTestTrait for MySQL --- src/Traits/DatabaseTestTrait.php | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Traits/DatabaseTestTrait.php b/src/Traits/DatabaseTestTrait.php index f69690e..c847433 100644 --- a/src/Traits/DatabaseTestTrait.php +++ b/src/Traits/DatabaseTestTrait.php @@ -34,7 +34,6 @@ protected function setUpDatabase(string $schemaFile = null): void $this->getConnection(); - $this->unsetStatsExpiry(); $this->createTables(); $this->truncateTables(); @@ -53,6 +52,24 @@ protected function getConnection(): PDO return $this->container->get(PDO::class); } + /** + * Create tables. + * + * @return void + */ + protected function createTables(): void + { + if (defined('DB_TEST_TRAIT_INIT')) { + return; + } + + $this->unsetStatsExpiry(); + $this->dropTables(); + $this->importSchema(); + + define('DB_TEST_TRAIT_INIT', 1); + } + /** * Workaround for MySQL 8: update_time not working. * @@ -62,10 +79,10 @@ protected function getConnection(): PDO */ private function unsetStatsExpiry() { - $isMySql = strpos($this->getDatabaseVariable('version_comment'), 'MySQL') !== false; + $isMariaDb = strpos($this->getDatabaseVariable('version_comment'), 'MariaDB') !== false; $version = $this->getDatabaseVariable('version'); - if ($isMySql && version_compare($version, '8.0.0') >= 0) { + if (!$isMariaDb && version_compare($version, '8.0.0', '>=') && version_compare($version, '10.0.0', '<')) { $this->getConnection()->exec('SET information_schema_stats_expiry=0;'); } } @@ -93,23 +110,6 @@ protected function getDatabaseVariable(string $variable): string return (string)$row['Value']; } - /** - * Create tables. - * - * @return void - */ - protected function createTables(): void - { - if (defined('DB_TEST_TRAIT_INIT')) { - return; - } - - $this->dropTables(); - $this->importSchema(); - - define('DB_TEST_TRAIT_INIT', 1); - } - /** * Clean up database. Truncate tables. *