Skip to content

Commit 4ad0714

Browse files
committed
fork test
1 parent ef7d822 commit 4ad0714

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--TEST--
2+
MySQL PDO->__construct() - URI
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) != 'WIN') {
6+
die('skip only for Windows');
7+
}
8+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
9+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
10+
MySQLPDOTest::skip();
11+
?>
12+
--FILE--
13+
<?php
14+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
15+
16+
try {
17+
18+
if ($tmp = MySQLPDOTest::getTempDir()) {
19+
20+
$file = $tmp . DIRECTORY_SEPARATOR . 'pdomuri.tst';
21+
$dsn = MySQLPDOTest::getDSN();
22+
$user = PDO_MYSQL_TEST_USER;
23+
$pass = PDO_MYSQL_TEST_PASS;
24+
$uri = sprintf('uri:file:%s', $file);
25+
26+
if ($fp = @fopen($file, 'w')) {
27+
// ok, great we can create a file with a DSN in it
28+
fwrite($fp, $dsn);
29+
fclose($fp);
30+
clearstatcache();
31+
assert(file_exists($file));
32+
try {
33+
$db = new PDO($uri, $user, $pass);
34+
} catch (PDOException $e) {
35+
printf("[002] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n",
36+
$uri, $dsn,
37+
$file, filesize($file), file_get_contents($file),
38+
$e->getMessage());
39+
}
40+
unlink($file);
41+
}
42+
43+
if ($fp = @fopen($file, 'w')) {
44+
fwrite($fp, sprintf('mysql:dbname=letshopeinvalid;%s%s',
45+
chr(0), $dsn));
46+
fclose($fp);
47+
clearstatcache();
48+
assert(file_exists($file));
49+
try {
50+
$db = new PDO($uri, $user, $pass);
51+
} catch (PDOException $e) {
52+
printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), chr(0) test, %s\n",
53+
$uri, $dsn,
54+
$file, filesize($file), file_get_contents($file),
55+
$e->getMessage());
56+
}
57+
unlink($file);
58+
}
59+
60+
}
61+
62+
/* TODO: safe mode */
63+
64+
} catch (PDOException $e) {
65+
printf("[001] %s, [%s] %s\n",
66+
$e->getMessage(),
67+
(is_object($db)) ? $db->errorCode() : 'n/a',
68+
(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
69+
}
70+
71+
print "done!";
72+
?>
73+
--EXPECTF--
74+
Warning: PDO::__construct(file:%spdomuri.tst): failed to open stream: Invalid argument 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:%spdomuri.tst): failed to open stream: Invalid argument 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
79+
done!

ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
MySQL PDO->__construct() - URI
33
--SKIPIF--
44
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die('skip not for Windows');
7+
}
58
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
69
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
710
MySQLPDOTest::skip();

0 commit comments

Comments
 (0)