Skip to content

Commit f4c97fa

Browse files
committed
Optimize DatabaseTestTrait for MySQL
1 parent 854706b commit f4c97fa

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Traits/DatabaseTestTrait.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ protected function createTables(): void
7979
*/
8080
private function unsetStatsExpiry()
8181
{
82-
$isMariaDb = strpos($this->getDatabaseVariable('version_comment'), 'MariaDB') !== false;
83-
$version = $this->getDatabaseVariable('version');
82+
$expiry = $this->getDatabaseVariable('information_schema_stats_expiry');
83+
$version = (string)$this->getDatabaseVariable('version');
8484

85-
if (!$isMariaDb && version_compare($version, '8.0.0', '>=') && version_compare($version, '10.0.0', '<')) {
85+
if ($expiry !== null && version_compare($version, '8.0.0', '>=')) {
8686
$this->getConnection()->exec('SET information_schema_stats_expiry=0;');
8787
}
8888
}
@@ -92,9 +92,9 @@ private function unsetStatsExpiry()
9292
*
9393
* @param string $variable The variable
9494
*
95-
* @return string The value
95+
* @return string|null The value
9696
*/
97-
protected function getDatabaseVariable(string $variable): string
97+
protected function getDatabaseVariable(string $variable): ?string
9898
{
9999
$statement = $this->getConnection()->prepare('SHOW VARIABLES LIKE ?');
100100
if (!$statement || $statement->execute([$variable]) === false) {
@@ -104,7 +104,8 @@ protected function getDatabaseVariable(string $variable): string
104104
$row = $statement->fetch(PDO::FETCH_ASSOC);
105105

106106
if ($row === false) {
107-
throw new UnexpectedValueException(sprintf('Database variable not defined: %s', $variable));
107+
// Database variable not defined
108+
return null;
108109
}
109110

110111
return (string)$row['Value'];

0 commit comments

Comments
 (0)