Merge pull request #7509 from kenjis/test-db-getVersion

fix: PostgreSQL getVersion() output
This commit is contained in:
kenjis 2023-05-21 19:57:06 +09:00 committed by GitHub
commit dee68ccf70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -133,7 +133,9 @@ class Connection extends BaseConnection
}
$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'];
}

View File

@ -0,0 +1,34 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* 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);
}
}