Skip to content

Commit 3d0a784

Browse files
committed
fixup! DBAL3: Implement getServerVersion(), forwarding to PDOCrateDB
1 parent d89797a commit 3d0a784

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/Crate/DBAL/Driver/PDOCrate/PDOConnection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public function __construct($dsn, $user = null, $password = null, ?array $option
5252

5353
public function getServerVersion(): string
5454
{
55-
return $this->connection->getServerVersion();
55+
try {
56+
return $this->connection->getServerVersion();
57+
} catch (PDOException $exception) {
58+
throw Exception::new($exception);
59+
}
5660
}
5761

5862
public function getNativeConnection(): PDOCrateDB

test/Crate/Test/DBAL/Functional/ConnectionTest.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,29 @@ public function testConnect()
9696
$this->assertEquals('crate', $row['name']);
9797
}
9898

99-
public function testGetServerVersion()
99+
public function testGetServerVersionNativeConnection()
100100
{
101101
// Retrieve server version.
102102
$serverVersion = $this->_conn->getNativeConnection()->getServerVersion();
103+
$this->assertNotNull($serverVersion, 'Server version should not be null');
104+
$this->assertNotEquals('0.0.0', $serverVersion, 'Server version should not be 0.0.0');
105+
$this->assertMatchesRegularExpression(
106+
'/^\d+\.\d+\.\d+/',
107+
$serverVersion,
108+
'Server version should follow semantic versioning'
109+
);
110+
}
103111

104-
// Assume tests are running against CrateDB 5.x or higher, which is likely,
105-
// because it will mostly be running on CrateDB nightly.
106-
// Otherwise, we will need to populate this value from an external source,
107-
// for example an environment variable populated by a CI build matrix.
108-
$this->assertTrue(
109-
version_compare($serverVersion, '5.0.0', '>='),
110-
'Server version should be at least 5.0.0',
112+
public function testGetServerVersionWrappedConnection()
113+
{
114+
// Retrieve server version.
115+
$serverVersion = $this->_conn->getWrappedConnection()->getServerVersion();
116+
$this->assertNotNull($serverVersion, 'Server version should not be null');
117+
$this->assertNotEquals('0.0.0', $serverVersion, 'Server version should not be 0.0.0');
118+
$this->assertMatchesRegularExpression(
119+
'/^\d+\.\d+\.\d+/',
120+
$serverVersion,
121+
'Server version should follow semantic versioning'
111122
);
112123
}
113124

0 commit comments

Comments
 (0)