Skip to content

Commit de8b026

Browse files
committed
#19: exec\007-exec_vs_shell_exec_comparison.phpt - Test stabilization
1 parent bc274d6 commit de8b026

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

tests/exec/007-exec_vs_shell_exec_comparison.phpt

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,57 @@ if (!function_exists("exec") || !function_exists("shell_exec")) {
1010
<?php
1111

1212
use function Async\spawn;
13+
use function Async\awaitAll;
1314

1415
echo "Starting comparison test\n";
1516

16-
spawn(function () {
17-
echo "Testing exec() async\n";
18-
19-
$php = getenv('TEST_PHP_EXECUTABLE');
20-
if ($php === false) {
21-
die("skip no php executable defined");
22-
}
23-
24-
$output = [];
25-
$return_var = null;
26-
27-
exec($php . ' -r "echo \'exec result\';"', $output, $return_var);
28-
29-
echo "exec() result: " . implode("", $output) . " (code: $return_var)\n";
30-
});
17+
$results = [];
3118

32-
spawn(function () {
33-
echo "Testing shell_exec() async\n";
34-
35-
$php = getenv('TEST_PHP_EXECUTABLE');
36-
if ($php === false) {
37-
die("skip no php executable defined");
38-
}
19+
$tasks = [
20+
spawn(function () use (&$results) {
21+
echo "Testing exec() async\n";
22+
23+
$php = getenv('TEST_PHP_EXECUTABLE');
24+
if ($php === false) {
25+
die("skip no php executable defined");
26+
}
27+
28+
$output = [];
29+
$return_var = null;
30+
31+
exec($php . ' -r "echo \'exec result\';"', $output, $return_var);
32+
33+
$results[] = "exec() result: " . implode("", $output) . " (code: $return_var)";
34+
}),
3935

40-
$output = shell_exec($php . ' -r "usleep(50);echo \'shell_exec result\';"');
36+
spawn(function () use (&$results) {
37+
echo "Testing shell_exec() async\n";
38+
39+
$php = getenv('TEST_PHP_EXECUTABLE');
40+
if ($php === false) {
41+
die("skip no php executable defined");
42+
}
43+
44+
$output = shell_exec($php . ' -r "usleep(50);echo \'shell_exec result\';"');
45+
46+
$results[] = "shell_exec() result: " . trim($output);
47+
}),
4148

42-
echo "shell_exec() result: " . trim($output) . "\n";
43-
});
44-
45-
spawn(function() {
46-
echo "Background task running\n";
47-
});
49+
spawn(function() {
50+
echo "Background task running\n";
51+
})
52+
];
4853

4954
echo "Comparison test completed\n";
55+
56+
// Wait for all tasks to complete
57+
awaitAll($tasks);
58+
59+
// Sort and output results
60+
sort($results);
61+
foreach ($results as $result) {
62+
echo $result . "\n";
63+
}
5064
?>
5165
--EXPECT--
5266
Starting comparison test

0 commit comments

Comments
 (0)