Skip to content

Commit cf701fb

Browse files
Optimized pdo_pgsql connection test (#12454)
1 parent 3eba1a8 commit cf701fb

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

ext/pdo_pgsql/tests/gh12423.phpt

Lines changed: 26 additions & 19 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,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

27-
echo "dsn without credentials / correct user / correct password\n";
34+
echo "dsn without credentials / correct user / correct password".PHP_EOL;
2835
try {
2936
$db = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
30-
echo "Connected.\n\n";
37+
echo "Connected.".PHP_EOL.PHP_EOL;
3138
} catch (PDOException $e) {
32-
echo $e->getMessage();
39+
echo $e->getMessage().PHP_EOL;
3340
}
3441

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

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

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

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

0 commit comments

Comments
 (0)