@@ -22,10 +22,7 @@ public function testQueryExampleReturnsCalculatedValueFromPlaceholderVariables()
22
22
23
23
public function testQueryExampleExecutedWithCgiReturnsDefaultValueAfterContentTypeHeader ()
24
24
{
25
- $ code = 1 ;
26
- $ null = DIRECTORY_SEPARATOR === '\\' ? 'NUL ' : '/dev/null ' ;
27
- system ("php-cgi --version > $ null 2> $ null " , $ code );
28
- if ($ code !== 0 ) {
25
+ if (!$ this ->canExecute ('php-cgi --version ' )) {
29
26
$ this ->markTestSkipped ('Unable to execute "php-cgi" ' );
30
27
}
31
28
@@ -34,6 +31,37 @@ public function testQueryExampleExecutedWithCgiReturnsDefaultValueAfterContentTy
34
31
$ this ->assertStringEndsWith ("\r\n\r\n" . 'value ' . PHP_EOL . '42 ' . PHP_EOL , $ output );
35
32
}
36
33
34
+ public function testQueryExampleWithOpenBasedirRestrictedRunsDefaultPhpAndReturnsDefaultValue ()
35
+ {
36
+ if (!$ this ->canExecute ('php --version ' )) {
37
+ $ this ->markTestSkipped ('Unable to execute "php" ' );
38
+ }
39
+
40
+ $ output = $ this ->execExample (escapeshellarg (PHP_BINARY ) . ' -dopen_basedir= ' . escapeshellarg (dirname (__DIR__ )) . ' query.php ' );
41
+
42
+ $ this ->assertEquals ('value ' . PHP_EOL . '42 ' . PHP_EOL , $ output );
43
+ }
44
+
45
+ public function testQueryExampleExecutedWithCgiAndOpenBasedirRestrictedRunsDefaultPhpAndReturnsDefaultValueAfterContentTypeHeader ()
46
+ {
47
+ if (!$ this ->canExecute ('php-cgi --version ' ) || !$ this ->canExecute ('php --version ' )) {
48
+ $ this ->markTestSkipped ('Unable to execute "php-cgi" or "php" ' );
49
+ }
50
+
51
+ $ output = $ this ->execExample ('php-cgi -dopen_basedir= ' . escapeshellarg (dirname (__DIR__ )) . ' query.php ' );
52
+
53
+ $ this ->assertStringEndsWith ("\r\n\r\n" . 'value ' . PHP_EOL . '42 ' . PHP_EOL , $ output );
54
+ }
55
+
56
+ private function canExecute ($ command )
57
+ {
58
+ $ code = 1 ;
59
+ $ null = DIRECTORY_SEPARATOR === '\\' ? 'NUL ' : '/dev/null ' ;
60
+ system ("$ command > $ null 2> $ null " , $ code );
61
+
62
+ return $ code === 0 ;
63
+ }
64
+
37
65
private function execExample ($ command )
38
66
{
39
67
chdir (__DIR__ . '/../examples/ ' );
0 commit comments