diff options
author | Xinchen Hui <laruence@php.net> | 2011-09-20 07:10:46 +0000 |
---|---|---|
committer | Xinchen Hui <laruence@php.net> | 2011-09-20 07:10:46 +0000 |
commit | 552bfa8156666b7b15ca49f90a2e7feccd74eef6 (patch) | |
tree | 9f063b9e2187cce0ecd1d39d7c60bf8d10cca3d6 | |
parent | eb233a26f7c9d9eb58dd5c1c0363310982bf0350 (diff) | |
download | php-git-552bfa8156666b7b15ca49f90a2e7feccd74eef6.tar.gz |
Add tests for built-in webserver
-rw-r--r-- | sapi/cli/tests/php_cli_server.inc | 29 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_001.phpt | 21 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_002.phpt | 23 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_003.phpt | 23 |
4 files changed, 96 insertions, 0 deletions
diff --git a/sapi/cli/tests/php_cli_server.inc b/sapi/cli/tests/php_cli_server.inc new file mode 100644 index 0000000000..012efa704f --- /dev/null +++ b/sapi/cli/tests/php_cli_server.inc @@ -0,0 +1,29 @@ +<?php +define ("PHP_CLI_SERVER_ADDRESS", "localhost:8964"); + +function php_cli_server_start($php_executable, $code = 'echo "Hello world";') { + $doc_root = __DIR__; + $router = "router.php"; + file_put_contents($doc_root . '/' . $router, '<?php ' . $code . ' ?>'); + + $descriptorspec = array( + 0 => STDIN, + 1 => STDOUT, + 2 => STDERR, + ); + + $cmd = "{$php_executable} -t {$doc_root} -S " . PHP_CLI_SERVER_ADDRESS . " {$router}"; + + $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root); + sleep(1); + + return $handle; +} + +function php_cli_server_shutdown($handle) { + proc_terminate($handle); + proc_close($handle); + @unlink(__DIR__ . "router.php"); + return true; +} +?> diff --git a/sapi/cli/tests/php_cli_server_001.phpt b/sapi/cli/tests/php_cli_server_001.phpt new file mode 100644 index 0000000000..69ff6a1fdc --- /dev/null +++ b/sapi/cli/tests/php_cli_server_001.phpt @@ -0,0 +1,21 @@ +--TEST-- +basic function +--INI-- +allow_url_fopen = TRUE +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php +include "php_cli_server.inc"; +$php = getenv('TEST_PHP_EXECUTABLE'); +$handle = php_cli_server_start($php); +var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); +php_cli_server_shutdown($handle); +?> +--EXPECT-- +string(11) "Hello world" diff --git a/sapi/cli/tests/php_cli_server_002.phpt b/sapi/cli/tests/php_cli_server_002.phpt new file mode 100644 index 0000000000..02a813307d --- /dev/null +++ b/sapi/cli/tests/php_cli_server_002.phpt @@ -0,0 +1,23 @@ +--TEST-- +$_SERVER variable +--INI-- +allow_url_fopen = TRUE +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php +include "php_cli_server.inc"; +$php = getenv('TEST_PHP_EXECUTABLE'); +$handle = php_cli_server_start($php, 'var_dump($_SERVER["DOCUMENT_ROOT"], $_SERVER["SERVER_SOFTWARE"]);'); +var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); +php_cli_server_shutdown($handle); +?> +--EXPECTF-- +string(%d) "string(%d) "%s/tests" +string(%d) "PHP %s Development Server" +" diff --git a/sapi/cli/tests/php_cli_server_003.phpt b/sapi/cli/tests/php_cli_server_003.phpt new file mode 100644 index 0000000000..9e8e8e6527 --- /dev/null +++ b/sapi/cli/tests/php_cli_server_003.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #55726 (Changing the working directory makes router script inaccessible) +--INI-- +allow_url_fopen = 1 +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php +include "php_cli_server.inc"; +$php = getenv('TEST_PHP_EXECUTABLE'); +$handle = php_cli_server_start($php, 'chdir("/tmp"); echo "okey";'); +var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); +var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); +php_cli_server_shutdown($handle); +?> +--EXPECTF-- +string(4) "okey" +string(4) "okey" |