Skip to content

Commit 854706b

Browse files
committed
Fix DatabaseTestTrait for MySQL
1 parent c71210d commit 854706b

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/Traits/DatabaseTestTrait.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ protected function setUpDatabase(string $schemaFile = null): void
3434

3535
$this->getConnection();
3636

37-
$this->unsetStatsExpiry();
3837
$this->createTables();
3938
$this->truncateTables();
4039

@@ -53,6 +52,24 @@ protected function getConnection(): PDO
5352
return $this->container->get(PDO::class);
5453
}
5554

55+
/**
56+
* Create tables.
57+
*
58+
* @return void
59+
*/
60+
protected function createTables(): void
61+
{
62+
if (defined('DB_TEST_TRAIT_INIT')) {
63+
return;
64+
}
65+
66+
$this->unsetStatsExpiry();
67+
$this->dropTables();
68+
$this->importSchema();
69+
70+
define('DB_TEST_TRAIT_INIT', 1);
71+
}
72+
5673
/**
5774
* Workaround for MySQL 8: update_time not working.
5875
*
@@ -62,10 +79,10 @@ protected function getConnection(): PDO
6279
*/
6380
private function unsetStatsExpiry()
6481
{
65-
$isMySql = strpos($this->getDatabaseVariable('version_comment'), 'MySQL') !== false;
82+
$isMariaDb = strpos($this->getDatabaseVariable('version_comment'), 'MariaDB') !== false;
6683
$version = $this->getDatabaseVariable('version');
6784

68-
if ($isMySql && version_compare($version, '8.0.0') >= 0) {
85+
if (!$isMariaDb && version_compare($version, '8.0.0', '>=') && version_compare($version, '10.0.0', '<')) {
6986
$this->getConnection()->exec('SET information_schema_stats_expiry=0;');
7087
}
7188
}
@@ -93,23 +110,6 @@ protected function getDatabaseVariable(string $variable): string
93110
return (string)$row['Value'];
94111
}
95112

96-
/**
97-
* Create tables.
98-
*
99-
* @return void
100-
*/
101-
protected function createTables(): void
102-
{
103-
if (defined('DB_TEST_TRAIT_INIT')) {
104-
return;
105-
}
106-
107-
$this->dropTables();
108-
$this->importSchema();
109-
110-
define('DB_TEST_TRAIT_INIT', 1);
111-
}
112-
113113
/**
114114
* Clean up database. Truncate tables.
115115
*

0 commit comments

Comments
 (0)