mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-8.1'
* PHP-8.1: Fix PDO URI test
This commit is contained in:
commit
e7a79719cc
1 changed files with 6 additions and 23 deletions
|
@ -19,10 +19,9 @@ MySQLPDOTest::skip();
|
||||||
$dsn = MySQLPDOTest::getDSN();
|
$dsn = MySQLPDOTest::getDSN();
|
||||||
$user = PDO_MYSQL_TEST_USER;
|
$user = PDO_MYSQL_TEST_USER;
|
||||||
$pass = PDO_MYSQL_TEST_PASS;
|
$pass = PDO_MYSQL_TEST_PASS;
|
||||||
$uri = sprintf('uri:file://%s', (substr(PHP_OS, 0, 3) == 'WIN' ? str_replace('\\', '/', $file) : $file));
|
$uri = 'uri:file://' . $file;
|
||||||
|
|
||||||
if ($fp = @fopen($file, 'w')) {
|
if ($fp = @fopen($file, 'w')) {
|
||||||
// ok, great we can create a file with a DSN in it
|
|
||||||
fwrite($fp, $dsn);
|
fwrite($fp, $dsn);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
|
@ -39,38 +38,23 @@ MySQLPDOTest::skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fp = @fopen($file, 'w')) {
|
if ($fp = @fopen($file, 'w')) {
|
||||||
fwrite($fp, sprintf('mysql:dbname=letshopeinvalid;%s%s',
|
fwrite($fp, $dsn . chr(0) . ';host=nonsense;unix_socket=nonsense');
|
||||||
chr(0), $dsn));
|
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
assert(file_exists($file));
|
assert(file_exists($file));
|
||||||
try {
|
try {
|
||||||
$db = new PDO($uri, $user, $pass);
|
$db = new PDO($uri, $user, $pass);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$expected = array(
|
printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n",
|
||||||
"SQLSTATE[HY000] [1049]",
|
$uri, $dsn,
|
||||||
"SQLSTATE[42000] [1049]",
|
$file, filesize($file), file_get_contents($file),
|
||||||
"SQLSTATE[HY000] [2002]"
|
$e->getMessage());
|
||||||
);
|
|
||||||
$isExpected = false;
|
|
||||||
foreach ($expected as $prefix) {
|
|
||||||
if (str_starts_with($e->getMessage(), $prefix)) {
|
|
||||||
$isExpected = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), chr(0) test, %s\n",
|
|
||||||
$uri, $dsn,
|
|
||||||
$file, filesize($file), file_get_contents($file),
|
|
||||||
($isExpected ? 'EXPECTED ERROR' : $e->getMessage()));
|
|
||||||
}
|
}
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: safe mode */
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
printf("[001] %s, [%s] %s\n",
|
printf("[001] %s, [%s] %s\n",
|
||||||
$e->getMessage(),
|
$e->getMessage(),
|
||||||
|
@ -81,5 +65,4 @@ MySQLPDOTest::skip();
|
||||||
print "done!";
|
print "done!";
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
[003] URI=uri:file://%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, EXPECTED ERROR
|
|
||||||
done!
|
done!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue