@@ -22,10 +22,7 @@ public function testQueryExampleReturnsCalculatedValueFromPlaceholderVariables()
2222
2323 public function testQueryExampleExecutedWithCgiReturnsDefaultValueAfterContentTypeHeader ()
2424 {
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 ' )) {
2926 $ this ->markTestSkipped ('Unable to execute "php-cgi" ' );
3027 }
3128
@@ -34,6 +31,37 @@ public function testQueryExampleExecutedWithCgiReturnsDefaultValueAfterContentTy
3431 $ this ->assertStringEndsWith ("\r\n\r\n" . 'value ' . PHP_EOL . '42 ' . PHP_EOL , $ output );
3532 }
3633
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+
3765 private function execExample ($ command )
3866 {
3967 chdir (__DIR__ . '/../examples/ ' );
0 commit comments