Skip to content

Commit 00a22d4

Browse files
committed
Improved test for bug #62479
1 parent fa6aaf8 commit 00a22d4

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

ext/pdo_pgsql/tests/bug62479.phpt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,42 @@ if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not lo
66
require dirname(__FILE__) . '/config.inc';
77
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
88
PDOTest::skip();
9-
if (!isset($conf['ENV']['PDOTEST_DSN'])) die('no dsn found in env');
9+
10+
$dsn = getenv('PDOTEST_DSN');
11+
if (empty($dsn)) die('skip no dsn found in env');
12+
1013
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
11-
$rand = rand(5, 5);
14+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
16+
17+
$user = 'pdo_test_'.rand(5, 400);
18+
$pass = 'testpass';
19+
20+
// Assume that if we can't create or drop a user, this test needs to be skipped
21+
try {
22+
$db->exec("DROP USER IF EXISTS $user");
23+
$db->exec("CREATE USER $user WITH PASSWORD '$pass'");
24+
} catch (PDOException $e) {
25+
die("skip You need CREATEUSER permissions to run the test");
26+
}
27+
28+
// Peer authentication might prevent the test from properly running
29+
try {
30+
$testConn = new PDO($dsn, $user, $pass);
31+
} catch (PDOException $e) {
32+
echo "skip ".$e->getMessage();
33+
}
34+
35+
$db->exec("DROP USER $user");
1236

13-
// Assume that if we can't create a user, this test needs to be skipped
14-
$testQuery = "CREATE USER pdo_$rand WITH PASSWORD 'testpass'";
15-
$db->query($testQuery);
16-
$testQuery = "DROP USER pdo_$rand";
17-
$db->query($testQuery);
1837
?>
1938
--FILE--
2039
<?php
2140
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
2241
$pdo = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
2342
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
2443
$rand = rand(5, 400);
25-
$user = "pdo_$rand";
44+
$user = "pdo_test_$rand";
2645
$template = "CREATE USER $user WITH PASSWORD '%s'";
2746
$dropUser = "DROP USER $user";
2847
$testQuery = 'SELECT 1 as verification';

0 commit comments

Comments
 (0)