Skip to content

Commit a7dcc55

Browse files
committed
Optimized pdo_pgsql connection test
add skip conditions add line break on error, fix skip message
1 parent 4dcf063 commit a7dcc55

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ext/pdo_pgsql/tests/gh12423.phpt

+16-9
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,53 +20,55 @@ $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 {
2936
$db = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
3037
echo "Connected.\n\n";
3138
} catch (PDOException $e) {
32-
echo $e->getMessage();
39+
echo $e->getMessage()."\n";
3340
}
3441

3542
echo "dsn with credentials / no user / no password\n";
3643
try {
3744
$db = new PDO("{$dsn} user={$user} password={$password}", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
3845
echo "Connected.\n\n";
3946
} catch (PDOException $e) {
40-
echo $e->getMessage();
47+
echo $e->getMessage()."\n";
4148
}
4249

4350
echo "dsn with correct user / incorrect user / correct password\n";
4451
try {
4552
$db = new PDO("{$dsn} user={$user}", 'hoge', $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
4653
echo "Connected.\n\n";
4754
} catch (PDOException $e) {
48-
echo $e->getMessage();
55+
echo $e->getMessage()."\n";
4956
}
5057

5158
echo "dsn with correct password / correct user / incorrect password\n";
5259
try {
5360
$db = new PDO("{$dsn} password={$password}", $user, 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
5461
echo "Connected.\n\n";
5562
} catch (PDOException $e) {
56-
echo $e->getMessage();
63+
echo $e->getMessage()."\n";
5764
}
5865

5966
echo "dsn with correct credentials / incorrect user / incorrect password\n";
6067
try {
6168
$db = new PDO("{$dsn} user={$user} password={$password}", 'hoge', 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
6269
echo "Connected.\n";
6370
} catch (PDOException $e) {
64-
echo $e->getMessage();
71+
echo $e->getMessage()."\n";
6572
}
6673
?>
6774
--EXPECT--

0 commit comments

Comments
 (0)