Skip to content

Commit 110a146

Browse files
committed
add tests for proc_open() and pipes
1 parent ad60549 commit 110a146

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
function create_sleep_script()
4+
{
5+
$fname = dirname(__FILE__) . DIRECTORY_SEPARATOR . "proc_open_pipes_sleep.php";
6+
7+
if (!file_exists($fname)) {
8+
file_put_contents($fname, "<?php\nsleep(1);\n");
9+
}
10+
11+
return $fname;
12+
}
13+
14+
function unlink_sleep_script()
15+
{
16+
$fname = dirname(__FILE__) . DIRECTORY_SEPARATOR . "proc_open_pipes_sleep.php";
17+
18+
if (file_exists($fname)) {
19+
unlink($fname);
20+
}
21+
}
22+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
--TEST--
2+
proc_open() with > 16 pipes
3+
--FILE--
4+
<?php
5+
6+
include dirname(__FILE__) . "/proc_open_pipes.inc";
7+
8+
for ($i = 3; $i<= 30; $i++) {
9+
$spec[$i] = array('pipe', 'w');
10+
}
11+
12+
$php = getenv("TEST_PHP_EXECUTABLE");
13+
$callee = create_sleep_script();
14+
proc_open("$php $callee", $spec, $pipes);
15+
16+
var_dump(count($spec));
17+
var_dump($pipes);
18+
19+
?>
20+
--CLEAN--
21+
<?php
22+
include dirname(__FILE__) . "/proc_open_pipes.inc";
23+
24+
unlink_sleep_script();
25+
26+
?>
27+
--EXPECTF--
28+
int(28)
29+
array(28) {
30+
[3]=>
31+
resource(%d) of type (Unknown)
32+
[4]=>
33+
resource(%d) of type (Unknown)
34+
[5]=>
35+
resource(%d) of type (Unknown)
36+
[6]=>
37+
resource(%d) of type (Unknown)
38+
[7]=>
39+
resource(%d) of type (Unknown)
40+
[8]=>
41+
resource(%d) of type (Unknown)
42+
[9]=>
43+
resource(%d) of type (Unknown)
44+
[10]=>
45+
resource(%d) of type (Unknown)
46+
[11]=>
47+
resource(%d) of type (Unknown)
48+
[12]=>
49+
resource(%d) of type (Unknown)
50+
[13]=>
51+
resource(%d) of type (Unknown)
52+
[14]=>
53+
resource(%d) of type (Unknown)
54+
[15]=>
55+
resource(%d) of type (Unknown)
56+
[16]=>
57+
resource(%d) of type (Unknown)
58+
[17]=>
59+
resource(%d) of type (Unknown)
60+
[18]=>
61+
resource(%d) of type (Unknown)
62+
[19]=>
63+
resource(%d) of type (Unknown)
64+
[20]=>
65+
resource(%d) of type (Unknown)
66+
[21]=>
67+
resource(%d) of type (Unknown)
68+
[22]=>
69+
resource(%d) of type (Unknown)
70+
[23]=>
71+
resource(%d) of type (Unknown)
72+
[24]=>
73+
resource(%d) of type (Unknown)
74+
[25]=>
75+
resource(%d) of type (Unknown)
76+
[26]=>
77+
resource(%d) of type (Unknown)
78+
[27]=>
79+
resource(%d) of type (Unknown)
80+
[28]=>
81+
resource(%d) of type (Unknown)
82+
[29]=>
83+
resource(%d) of type (Unknown)
84+
[30]=>
85+
resource(%d) of type (Unknown)
86+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
proc_open() with no pipes
3+
--FILE--
4+
<?php
5+
6+
include dirname(__FILE__) . "/proc_open_pipes.inc";
7+
8+
$spec = array();
9+
10+
$php = getenv("TEST_PHP_EXECUTABLE");
11+
$callee = create_sleep_script();
12+
proc_open("$php $callee", $spec, $pipes);
13+
14+
var_dump(count($spec));
15+
var_dump($pipes);
16+
17+
?>
18+
--CLEAN--
19+
<?php
20+
include dirname(__FILE__) . "/proc_open_pipes.inc";
21+
22+
unlink_sleep_script();
23+
24+
?>
25+
--EXPECTF--
26+
int(0)
27+
array(0) {
28+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
proc_open() with invalid pipes
3+
--FILE--
4+
<?php
5+
6+
include dirname(__FILE__) . "/proc_open_pipes.inc";
7+
8+
for ($i = 3; $i<= 5; $i++) {
9+
$spec[$i] = array('pipe', 'w');
10+
}
11+
12+
$php = getenv("TEST_PHP_EXECUTABLE");
13+
$callee = create_sleep_script();
14+
15+
$spec[$i] = array('pi');
16+
proc_open("$php $callee", $spec, $pipes);
17+
18+
$spec[$i] = 1;
19+
proc_open("$php $callee", $spec, $pipes);
20+
21+
$spec[$i] = array('pipe', "test");
22+
proc_open("$php $callee", $spec, $pipes);
23+
var_dump($pipes);
24+
25+
$spec[$i] = array('file', "test", "z");
26+
proc_open("$php $callee", $spec, $pipes);
27+
var_dump($pipes);
28+
29+
echo "END\n";
30+
?>
31+
--CLEAN--
32+
<?php
33+
include dirname(__FILE__) . "/proc_open_pipes.inc";
34+
35+
unlink_sleep_script();
36+
37+
?>
38+
--EXPECTF--
39+
Warning: proc_open(): pi is not a valid descriptor spec/mode in %s on line %d
40+
41+
Warning: proc_open(): Descriptor item must be either an array or a File-Handle in %s on line %d
42+
array(4) {
43+
[3]=>
44+
resource(%d) of type (Unknown)
45+
[4]=>
46+
resource(%d) of type (Unknown)
47+
[5]=>
48+
resource(%d) of type (Unknown)
49+
[6]=>
50+
resource(%d) of type (Unknown)
51+
}
52+
53+
Warning: proc_open(test): failed to open stream: %s in %s on line %d
54+
array(4) {
55+
[3]=>
56+
resource(%d) of type (Unknown)
57+
[4]=>
58+
resource(%d) of type (Unknown)
59+
[5]=>
60+
resource(%d) of type (Unknown)
61+
[6]=>
62+
resource(%d) of type (Unknown)
63+
}
64+
END

0 commit comments

Comments
 (0)