From 00993a32cbaf4459c46b0ab63c0e2d70e067d157 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 21 May 2023 11:19:56 +0900 Subject: [PATCH 1/2] test: add test for getVersion() --- tests/system/Database/Live/GetVersionTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/system/Database/Live/GetVersionTest.php diff --git a/tests/system/Database/Live/GetVersionTest.php b/tests/system/Database/Live/GetVersionTest.php new file mode 100644 index 000000000000..30f4729b2944 --- /dev/null +++ b/tests/system/Database/Live/GetVersionTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Database\Live; + +use CodeIgniter\Test\CIUnitTestCase; +use CodeIgniter\Test\DatabaseTestTrait; + +/** + * @group DatabaseLive + * + * @internal + */ +final class GetVersionTest extends CIUnitTestCase +{ + use DatabaseTestTrait; + + protected $migrate = false; + + public function testGetVersion() + { + $version = $this->db->getVersion(); + + $this->assertMatchesRegularExpression('/\A\d+(\.\d+)*\z/', $version); + } +} From 55970d06f999a5eaecfb0235f4f52b6eb53e47ac Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 21 May 2023 18:53:22 +0900 Subject: [PATCH 2/2] fix: PostgreSQL version It seems PostgreSQL may return the version like '15.3 (Debian 15.3-1.pgdg110+1)'. --- system/Database/Postgre/Connection.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index bb790e48292c..8e96128264e2 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -133,7 +133,9 @@ public function getVersion(): string } $pgVersion = pg_version($this->connID); - $this->dataCache['version'] = $pgVersion['server'] ?? ''; + $this->dataCache['version'] = isset($pgVersion['server']) ? + (preg_match('/^(\d+\.\d+)/', $pgVersion['server'], $matches) ? $matches[1] : '') : + ''; return $this->dataCache['version']; }