Skip to content

Commit

Permalink
Fix DatabaseTestTrait for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Feb 20, 2021
1 parent c71210d commit 854706b
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/Traits/DatabaseTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ protected function setUpDatabase(string $schemaFile = null): void

$this->getConnection();

$this->unsetStatsExpiry();
$this->createTables();
$this->truncateTables();

Expand All @@ -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.
*
Expand All @@ -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;');
}
}
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 854706b

Please sign in to comment.