Skip to content

Commit dee68cc

Browse files
authored
Merge pull request #7509 from kenjis/test-db-getVersion
fix: PostgreSQL getVersion() output
2 parents d334a2a + 55970d0 commit dee68cc

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

system/Database/Postgre/Connection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ public function getVersion(): string
133133
}
134134

135135
$pgVersion = pg_version($this->connID);
136-
$this->dataCache['version'] = $pgVersion['server'] ?? '';
136+
$this->dataCache['version'] = isset($pgVersion['server']) ?
137+
(preg_match('/^(\d+\.\d+)/', $pgVersion['server'], $matches) ? $matches[1] : '') :
138+
'';
137139

138140
return $this->dataCache['version'];
139141
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter\Database\Live;
13+
14+
use CodeIgniter\Test\CIUnitTestCase;
15+
use CodeIgniter\Test\DatabaseTestTrait;
16+
17+
/**
18+
* @group DatabaseLive
19+
*
20+
* @internal
21+
*/
22+
final class GetVersionTest extends CIUnitTestCase
23+
{
24+
use DatabaseTestTrait;
25+
26+
protected $migrate = false;
27+
28+
public function testGetVersion()
29+
{
30+
$version = $this->db->getVersion();
31+
32+
$this->assertMatchesRegularExpression('/\A\d+(\.\d+)*\z/', $version);
33+
}
34+
}

0 commit comments

Comments
 (0)