Skip to content

Commit 076653a

Browse files
authored
fix(database): properly display mysql and postgresql versions in about command (#1258)
1 parent 05d9942 commit 076653a

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

packages/database/src/DatabaseInsightsProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ private function getDatabaseVersion(): Insight
4343
// TODO: support displaying multiple databases, after cache PR
4444
[$versionQuery, $regex] = match (get_class($this->databaseConfig)) {
4545
SQLiteConfig::class => ['SELECT sqlite_version() AS version;', '/(?<version>.*)/'],
46-
PostgresConfig::class => ['SELECT version() AS version;', '/(?<version>.*)/'],
47-
MysqlConfig::class => ['SELECT version() AS version;', "/PostgreSQL (?<version>\S+)/"],
46+
PostgresConfig::class => ['SELECT version() AS version;', "/PostgreSQL (?<version>\S+)/"],
47+
MysqlConfig::class => ['SELECT version() AS version;', '/^(?<version>\d+\.\d+\.\d+)(?:-\w+)?/'],
4848
default => [null, null],
4949
};
5050

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Tempest\Database\Tests;
4+
5+
use Generator;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
use PHPUnit\Framework\TestCase;
8+
use Tempest\Core\Insight;
9+
use Tempest\Database\Config\DatabaseConfig;
10+
use Tempest\Database\Config\MysqlConfig;
11+
use Tempest\Database\Config\PostgresConfig;
12+
use Tempest\Database\Config\SQLiteConfig;
13+
use Tempest\Database\Database;
14+
use Tempest\Database\DatabaseInsightsProvider;
15+
16+
final class DatabaseInsightsProviderTest extends TestCase
17+
{
18+
#[DataProvider('provide_database_drivers')]
19+
public function test_get_insights(DatabaseConfig $config, string $version, array $expected): void
20+
{
21+
$database = $this->createMock(Database::class);
22+
$database
23+
->expects($this->once())
24+
->method('fetchFirst')
25+
->withAnyParameters()
26+
->willReturn(['version' => $version]);
27+
28+
$databaseInsightsProvider = new DatabaseInsightsProvider(
29+
databaseConfig: $config,
30+
database: $database,
31+
);
32+
33+
$this->assertEquals($expected, $databaseInsightsProvider->getInsights());
34+
}
35+
36+
public static function provide_database_drivers(): Generator
37+
{
38+
yield 'sqlite' => [
39+
new SQLiteConfig(),
40+
'3.45.2',
41+
['Engine' => 'SQLite', 'Version' => new Insight('3.45.2')],
42+
];
43+
yield 'mysql (simple)' => [
44+
new MysqlConfig(),
45+
'8.0.42',
46+
['Engine' => 'MySQL', 'Version' => new Insight('8.0.42')],
47+
];
48+
yield 'mysql (distribution specific)' => [
49+
new MysqlConfig(),
50+
'8.0.42-0ubuntu0.22.04.1',
51+
['Engine' => 'MySQL', 'Version' => new Insight('8.0.42')],
52+
];
53+
yield 'postgresql' => [
54+
new PostgresConfig(),
55+
'PostgreSQL 15.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.3.0, 64-bit',
56+
['Engine' => 'PostgreSQL', 'Version' => new Insight('15.3')],
57+
];
58+
}
59+
}

0 commit comments

Comments
 (0)