From 136ef6f129330e8e3edbe5924039b2384578cf1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 2 May 2022 11:08:46 +0200 Subject: [PATCH] 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. --- .../tests/pdo_mysql___construct_uri.phpt | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt index 99cd631a4a2..982845499e2 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt @@ -18,10 +18,9 @@ MySQLPDOTest::skip(); $dsn = MySQLPDOTest::getDSN(); $user = PDO_MYSQL_TEST_USER; $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')) { - // ok, great we can create a file with a DSN in it fwrite($fp, $dsn); fclose($fp); clearstatcache(); @@ -38,31 +37,23 @@ MySQLPDOTest::skip(); } if ($fp = @fopen($file, 'w')) { - fwrite($fp, sprintf('mysql:dbname=letshopeinvalid;%s%s', - chr(0), $dsn)); + fwrite($fp, $dsn . chr(0) . ';host=nonsense;unix_socket=nonsense'); fclose($fp); clearstatcache(); assert(file_exists($file)); try { $db = new PDO($uri, $user, $pass); } catch (PDOException $e) { - $expected = array( - "SQLSTATE[HY000] [1049] Unknown database 'letshopeinvalid'", - "SQLSTATE[42000] [1049] Unknown database 'letshopeinvalid'", - "SQLSTATE[HY000] [2002] No such file or directory" - ); - 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), - (in_array($e->getMessage(), $expected) ? 'EXPECTED ERROR' : $e->getMessage())); + printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n", + $uri, $dsn, + $file, filesize($file), file_get_contents($file), + $e->getMessage()); } unlink($file); } } - /* TODO: safe mode */ - } catch (PDOException $e) { printf("[001] %s, [%s] %s\n", $e->getMessage(), @@ -73,5 +64,4 @@ MySQLPDOTest::skip(); print "done!"; ?> --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!