2
2
MySQL PDO->__construct() - URI
3
3
--SKIPIF--
4
4
<?php
5
- if (substr (PHP_OS , 0 , 3 ) == 'WIN ' ) {
6
- die ('skip not for Windows ' );
7
- }
8
5
require_once (__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc ' );
9
6
require_once (__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc ' );
10
7
MySQLPDOTest::skip ();
@@ -21,7 +18,7 @@ MySQLPDOTest::skip();
21
18
$ dsn = MySQLPDOTest::getDSN ();
22
19
$ user = PDO_MYSQL_TEST_USER ;
23
20
$ pass = PDO_MYSQL_TEST_PASS ;
24
- $ uri = sprintf ('uri:file:%s ' , $ file );
21
+ $ uri = sprintf ('uri:file:// %s ' , ( substr ( PHP_OS , 0 , 3 ) == ' WIN ' ? str_replace ( '\\' , ' / ' , $ file) : $ file ) );
25
22
26
23
if ($ fp = @fopen ($ file , 'w ' )) {
27
24
// ok, great we can create a file with a DSN in it
@@ -49,10 +46,14 @@ MySQLPDOTest::skip();
49
46
try {
50
47
$ db = new PDO ($ uri , $ user , $ pass );
51
48
} catch (PDOException $ e ) {
49
+ $ expected = array (
50
+ "SQLSTATE[HY000] [1049] Unknown database 'letshopeinvalid' " ,
51
+ "SQLSTATE[HY000] [2002] No such file or directory "
52
+ );
52
53
printf ("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), chr(0) test, %s \n" ,
53
54
$ uri , $ dsn ,
54
55
$ file , filesize ($ file ), file_get_contents ($ file ),
55
- $ e ->getMessage ());
56
+ ( in_array ( $ e ->getMessage (), $ expected ) ? ' EXPECTED ERROR ' : $ e -> getMessage () ));
56
57
}
57
58
unlink ($ file );
58
59
}
@@ -71,9 +72,5 @@ MySQLPDOTest::skip();
71
72
print "done! " ;
72
73
?>
73
74
--EXPECTF--
74
- Warning: PDO::__construct(file:/tmp/pdomuri.tst): failed to open stream: No such file or directory in %s on line %d
75
- [002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=%s'), invalid data source URI
76
-
77
- Warning: PDO::__construct(file:/tmp/pdomuri.tst): failed to open stream: No such file or directory in %s on line %d
78
- [003] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, invalid data source URI
75
+ [003] URI=uri:file://%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, EXPECTED ERROR
79
76
done!
0 commit comments