Skip to content

Commit 136ef6f

Browse files
mvorisekcmb69
authored andcommitted
Fix PDO URI test
Especially for remote servers, the respective part of the test may fail for a lot of different reasons; instead of trying to catch all, we rewrite to not fail, still testing for the contained NUL byte. Closes GH-8451.
1 parent 2d4cc0e commit 136ef6f

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ MySQLPDOTest::skip();
1818
$dsn = MySQLPDOTest::getDSN();
1919
$user = PDO_MYSQL_TEST_USER;
2020
$pass = PDO_MYSQL_TEST_PASS;
21-
$uri = sprintf('uri:file://%s', (substr(PHP_OS, 0, 3) == 'WIN' ? str_replace('\\', '/', $file) : $file));
21+
$uri = 'uri:file://' . $file;
2222

2323
if ($fp = @fopen($file, 'w')) {
24-
// ok, great we can create a file with a DSN in it
2524
fwrite($fp, $dsn);
2625
fclose($fp);
2726
clearstatcache();
@@ -38,31 +37,23 @@ MySQLPDOTest::skip();
3837
}
3938

4039
if ($fp = @fopen($file, 'w')) {
41-
fwrite($fp, sprintf('mysql:dbname=letshopeinvalid;%s%s',
42-
chr(0), $dsn));
40+
fwrite($fp, $dsn . chr(0) . ';host=nonsense;unix_socket=nonsense');
4341
fclose($fp);
4442
clearstatcache();
4543
assert(file_exists($file));
4644
try {
4745
$db = new PDO($uri, $user, $pass);
4846
} catch (PDOException $e) {
49-
$expected = array(
50-
"SQLSTATE[HY000] [1049] Unknown database 'letshopeinvalid'",
51-
"SQLSTATE[42000] [1049] Unknown database 'letshopeinvalid'",
52-
"SQLSTATE[HY000] [2002] No such file or directory"
53-
);
54-
printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), chr(0) test, %s\n",
55-
$uri, $dsn,
56-
$file, filesize($file), file_get_contents($file),
57-
(in_array($e->getMessage(), $expected) ? 'EXPECTED ERROR' : $e->getMessage()));
47+
printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n",
48+
$uri, $dsn,
49+
$file, filesize($file), file_get_contents($file),
50+
$e->getMessage());
5851
}
5952
unlink($file);
6053
}
6154

6255
}
6356

64-
/* TODO: safe mode */
65-
6657
} catch (PDOException $e) {
6758
printf("[001] %s, [%s] %s\n",
6859
$e->getMessage(),
@@ -73,5 +64,4 @@ MySQLPDOTest::skip();
7364
print "done!";
7465
?>
7566
--EXPECTF--
76-
[003] URI=uri:file://%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, EXPECTED ERROR
7767
done!

0 commit comments

Comments
 (0)