Skip to content

Commit 722cc99

Browse files
committed
Optimized pdo_pgsql connection test
add skip conditions
1 parent 221b4fe commit 722cc99

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

ext/pdo_pgsql/tests/gh12423.phpt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
--TEST--
22
GitHub #12424 (Fix GH-12423: [pdo_pgsql] Changed to prioritize DSN authentication information over arguments.)
3+
--EXTENSIONS--
4+
pdo
5+
pdo_pgsql
36
--SKIPIF--
47
<?php
5-
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
68
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
79
require __DIR__ . '/config.inc';
10+
if (strpos($config['ENV']['PDOTEST_DSN'], 'password=') === false && !isset($config['ENV']['PDOTEST_PASS'])) {
11+
die('skip: no password');
12+
}
813
PDOTest::skip();
914
?>
1015
--FILE--
@@ -15,14 +20,16 @@ $dsnWithCredentials = $config['ENV']['PDOTEST_DSN'];
1520
$user = $config['ENV']['PDOTEST_USER'] ?? null;
1621
$password = $config['ENV']['PDOTEST_PASS'] ?? null;
1722
if (!$user) {
18-
preg_match('/user=(.*?) /', $dsnWithCredentials, $match);
23+
preg_match('/user=([^ ]*?)/', $dsnWithCredentials, $match);
1924
$user = $match[1] ?? '';
2025
}
2126
if (!$password) {
22-
preg_match('/password=(.*?)$/', $dsnWithCredentials, $match);
27+
preg_match('/password=([^ ]*?)/', $dsnWithCredentials, $match);
2328
$password = $match[1] ?? '';
2429
}
25-
$dsn = str_replace(" user={$user} password={$password}", '', $dsnWithCredentials);
30+
$dsn = str_replace("user={$user}", '', $dsnWithCredentials);
31+
$dsn = str_replace("password={$password}", '', $dsn);
32+
$dsn = rtrim($dsn);
2633

2734
echo "dsn without credentials / correct user / correct password\n";
2835
try {

0 commit comments

Comments
 (0)