Skip to content

Commit 7f2228c

Browse files
committed
fixup! DBAL3: Implement getServerVersion(), forwarding to PDOCrateDB
1 parent 3ade28a commit 7f2228c

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
@@ -51,7 +51,11 @@ public function __construct($dsn, $user = null, $password = null, ?array $option
5151

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

5761
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
@@ -135,18 +135,29 @@ public function testRollbackWithoutBeginTransaction()
135135
$this->_conn->rollBack();
136136
}
137137

138-
public function testGetServerVersion()
138+
public function testGetServerVersionNativeConnection()
139139
{
140140
// Retrieve server version.
141141
$serverVersion = $this->_conn->getNativeConnection()->getServerVersion();
142+
$this->assertNotNull($serverVersion, 'Server version should not be null');
143+
$this->assertNotEquals('0.0.0', $serverVersion, 'Server version should not be 0.0.0');
144+
$this->assertMatchesRegularExpression(
145+
'/^\d+\.\d+\.\d+/',
146+
$serverVersion,
147+
'Server version should follow semantic versioning'
148+
);
149+
}
142150

143-
// Assume tests are running against CrateDB 5.x or higher, which is likely,
144-
// because it will mostly be running on CrateDB nightly.
145-
// Otherwise, we will need to populate this value from an external source,
146-
// for example an environment variable populated by a CI build matrix.
147-
$this->assertTrue(
148-
version_compare($serverVersion, '5.0.0', '>='),
149-
'Server version should be at least 5.0.0',
151+
public function testGetServerVersionWrappedConnection()
152+
{
153+
// Retrieve server version.
154+
$serverVersion = $this->_conn->getWrappedConnection()->getServerVersion();
155+
$this->assertNotNull($serverVersion, 'Server version should not be null');
156+
$this->assertNotEquals('0.0.0', $serverVersion, 'Server version should not be 0.0.0');
157+
$this->assertMatchesRegularExpression(
158+
'/^\d+\.\d+\.\d+/',
159+
$serverVersion,
160+
'Server version should follow semantic versioning'
150161
);
151162
}
152163

0 commit comments

Comments
 (0)