@@ -16,125 +16,128 @@ describe.each(['7.4'])('PHP %s', (phpVersion) => {
16
16
php = await NodePHP . load ( phpVersion ) ;
17
17
} ) ;
18
18
19
- it . skip ( 'proc_open() test with files' , async ( ) => {
20
- php . setPhpIniEntry ( 'disable_functions' , '' ) ;
21
- const result = await php . run ( {
22
- code : `<?php
23
- file_put_contents('/tmp/process_in', '');
24
- $res = proc_open(
25
- "echo WordPress",
26
- array(
27
- array("file","/tmp/process_in", "r"),
28
- array("file","/tmp/process_out", "w"),
29
- array("file","/tmp/process_err", "w"),
30
- ),
31
- $pipes
32
- );
33
-
34
- @file_get_contents("https://wordpress.org");
35
- sleep(1);
36
-
37
- $stdout = file_get_contents("/tmp/process_out");
38
- $stderr = file_get_contents("/tmp/process_err");
39
-
40
- echo 'stdout: ' . $stdout . "";
41
- echo 'stderr: ' . $stderr . PHP_EOL;
42
- ` ,
19
+ describe ( 'proc_open()' , ( ) => {
20
+ it ( 'echo – stdin=file (empty), stdout=file, stderr=file' , async ( ) => {
21
+ php . setPhpIniEntry ( 'disable_functions' , '' ) ;
22
+ const result = await php . run ( {
23
+ code : `<?php
24
+ file_put_contents('/tmp/process_in', '');
25
+ $res = proc_open(
26
+ "echo WordPress",
27
+ array(
28
+ array("file","/tmp/process_in", "r"),
29
+ array("file","/tmp/process_out", "w"),
30
+ array("file","/tmp/process_err", "w"),
31
+ ),
32
+ $pipes
33
+ );
34
+
35
+ // Yields back to JS event loop to capture and process the
36
+ // child_process output. This is fine. Regular PHP scripts
37
+ // typically wait for the child process to finish.
38
+ sleep(1);
39
+
40
+ $stdout = file_get_contents("/tmp/process_out");
41
+ $stderr = file_get_contents("/tmp/process_err");
42
+
43
+ echo 'stdout: ' . $stdout . "";
44
+ echo 'stderr: ' . $stderr . PHP_EOL;
45
+ ` ,
46
+ } ) ;
47
+ expect ( result . text ) . toEqual ( 'stdout: WordPress\nstderr: \n' ) ;
43
48
} ) ;
44
- console . log ( php . readFileAsText ( '/tmp/process_out' ) ) ;
45
- expect ( result . text ) . toEqual ( 'stdout: WordPress\nstderr: \n' ) ;
46
- } ) ;
47
49
48
- it . skip ( 'proc_open() test with pipes' , async ( ) => {
49
- php . setPhpIniEntry ( 'disable_functions' , '' ) ;
50
- const result = await php . run ( {
51
- code : `<?php
52
- file_put_contents('/tmp/process_in', '');
53
- $res = proc_open(
54
- "echo WordPress",
55
- array(
56
- array("file","/tmp/process_in", "r"),
57
- array("pipe","w"),
58
- array("pipe","w"),
59
- ),
60
- $pipes
61
- );
62
-
63
- $stdout = stream_get_contents($pipes[1]);
64
- $stderr = stream_get_contents($pipes[2]);
65
- proc_close($res);
66
-
67
- echo 'stdout: ' . $stdout . "";
68
- echo 'stderr: ' . $stderr . PHP_EOL;
69
- ` ,
50
+ it ( 'echo – stdin=file (empty), stdout=pipe, stderr=pipe' , async ( ) => {
51
+ php . setPhpIniEntry ( 'disable_functions' , '' ) ;
52
+ const result = await php . run ( {
53
+ code : `<?php
54
+ file_put_contents('/tmp/process_in', '');
55
+ $res = proc_open(
56
+ "echo WordPress",
57
+ array(
58
+ array("file","/tmp/process_in", "r"),
59
+ array("pipe","w"),
60
+ array("pipe","w"),
61
+ ),
62
+ $pipes
63
+ );
64
+
65
+ // stream_get_contents yields back to JS event loop internally.
66
+ $stdout = stream_get_contents($pipes[1]);
67
+ $stderr = stream_get_contents($pipes[2]);
68
+ proc_close($res);
69
+
70
+ echo 'stdout: ' . $stdout . "";
71
+ echo 'stderr: ' . $stderr . PHP_EOL;
72
+ ` ,
73
+ } ) ;
74
+ expect ( result . text ) . toEqual ( 'stdout: WordPress\nstderr: \n' ) ;
70
75
} ) ;
71
- expect ( result . text ) . toEqual ( 'stdout: WordPress\nstderr: \n' ) ;
72
- } ) ;
73
-
74
- // It works! :o NICE!
75
- it ( 'proc_open() test with stdin (pipe)' , async ( ) => {
76
- php . setPhpIniEntry ( 'disable_functions' , '' ) ;
77
- php . setPhpIniEntry ( 'allow_url_fopen' , '1' ) ;
78
- const result = await php . run ( {
79
- code : `<?php
80
- $res = proc_open(
81
- "cat",
82
- array(
83
- array("pipe","r"),
84
- array("file","/tmp/process_out", "w"),
85
- array("file","/tmp/process_err", "w"),
86
- ),
87
- $pipes
88
- );
89
- fwrite($pipes[0], 'WordPress\n');
90
-
91
- sleep(1);
92
76
93
- // And this is synchronous, too. We can't process the child_process
94
- // output in between these calls. We need to somehow yield back to JS
95
- // after writing to stdin.
96
- $stdout = file_get_contents("/tmp/process_out");
97
- $stderr = file_get_contents("/tmp/process_err");
98
- proc_close($res);
99
-
100
- echo 'stdout: ' . $stdout . "";
101
- echo 'stderr: ' . $stderr . PHP_EOL;
102
- ` ,
77
+ it ( 'cat – stdin=pipe, stdout=file, stderr=file' , async ( ) => {
78
+ php . setPhpIniEntry ( 'disable_functions' , '' ) ;
79
+ php . setPhpIniEntry ( 'allow_url_fopen' , '1' ) ;
80
+ const result = await php . run ( {
81
+ code : `<?php
82
+ $res = proc_open(
83
+ "cat",
84
+ array(
85
+ array("pipe","r"),
86
+ array("file","/tmp/process_out", "w"),
87
+ array("file","/tmp/process_err", "w"),
88
+ ),
89
+ $pipes
90
+ );
91
+ fwrite($pipes[0], 'WordPress\n');
92
+
93
+ // Yields back to JS event loop to capture and process the
94
+ // child_process output. This is fine. Regular PHP scripts
95
+ // typically wait for the child process to finish.
96
+ sleep(1);
97
+
98
+ $stdout = file_get_contents("/tmp/process_out");
99
+ $stderr = file_get_contents("/tmp/process_err");
100
+ proc_close($res);
101
+
102
+ echo 'stdout: ' . $stdout . "";
103
+ echo 'stderr: ' . $stderr . PHP_EOL;
104
+ ` ,
105
+ } ) ;
106
+ expect ( result . text ) . toEqual ( 'stdout: WordPress\nstderr: \n' ) ;
103
107
} ) ;
104
- expect ( result . text ) . toEqual ( 'stdout: WordPress\nstderr: \n' ) ;
105
- } ) ;
106
108
107
- it ( 'proc_open() test with stdin (file)' , async ( ) => {
108
- php . setPhpIniEntry ( 'disable_functions' , '' ) ;
109
- php . setPhpIniEntry ( 'allow_url_fopen' , '1' ) ;
110
- const result = await php . run ( {
111
- code : `<?php
112
- file_put_contents('/tmp/process_in', 'WordPress\n');
113
- $res = proc_open(
114
- "cat",
115
- array(
116
- array("file","/tmp/process_in", "r"),
117
- array("file","/tmp/process_out", "w"),
118
- array("file","/tmp/process_err", "w"),
119
- ),
120
- $pipes
121
- );
122
-
123
- sleep(1);
124
-
125
- // And this is synchronous, too. We can't process the child_process
126
- // output in between these calls. We need to somehow yield back to JS
127
- // after writing to stdin.
128
- $stdout = file_get_contents("/tmp/process_out");
129
- $stderr = file_get_contents("/tmp/process_err");
130
- proc_close($res);
109
+ it ( 'cat – stdin=file, stdout=file, stderr=file' , async ( ) => {
110
+ php . setPhpIniEntry ( 'disable_functions' , '' ) ;
111
+ php . setPhpIniEntry ( 'allow_url_fopen' , '1' ) ;
112
+ const result = await php . run ( {
113
+ code : `<?php
114
+ file_put_contents('/tmp/process_in', 'WordPress\n');
115
+ $res = proc_open(
116
+ "cat",
117
+ array(
118
+ array("file","/tmp/process_in", "r"),
119
+ array("file","/tmp/process_out", "w"),
120
+ array("file","/tmp/process_err", "w"),
121
+ ),
122
+ $pipes
123
+ );
124
+
125
+ // Yields back to JS event loop to capture and process the
126
+ // child_process output. This is fine. Regular PHP scripts
127
+ // typically wait for the child process to finish.
128
+ sleep(1);
129
+
130
+ $stdout = file_get_contents("/tmp/process_out");
131
+ $stderr = file_get_contents("/tmp/process_err");
132
+ proc_close($res);
133
+
134
+ echo 'stdout: ' . $stdout . "";
135
+ echo 'stderr: ' . $stderr . PHP_EOL;
136
+ ` ,
137
+ } ) ;
131
138
132
- echo 'stdout: ' . $stdout . "";
133
- echo 'stderr: ' . $stderr . PHP_EOL;
134
- ` ,
139
+ expect ( result . text ) . toEqual ( 'stdout: WordPress\nstderr: \n' ) ;
135
140
} ) ;
136
-
137
- expect ( result . text ) . toEqual ( 'stdout: WordPress\nstderr: \n' ) ;
138
141
} ) ;
139
142
140
143
describe ( 'Filesystem' , ( ) => {
0 commit comments