diff options
| author | Ondřej Surý <ondrej@sury.org> | 2012-05-28 16:52:15 +0200 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2012-05-28 16:52:15 +0200 |
| commit | 01c525f668ecff08bea21c4ff22745b8f77e8c3a (patch) | |
| tree | 07ebb675549d7a8ceb905676e4894151122321ac /sapi/cli/tests | |
| parent | d4d61a2bcb9975c8aeddbc6603211064174087a9 (diff) | |
| download | php-01c525f668ecff08bea21c4ff22745b8f77e8c3a.tar.gz | |
Imported Upstream version 5.4.4~rc1upstream/5.4.4_rc1
Diffstat (limited to 'sapi/cli/tests')
| -rw-r--r-- | sapi/cli/tests/bug61546.phpt | 22 | ||||
| -rw-r--r-- | sapi/cli/tests/bug61977.phpt | 157 | ||||
| -rw-r--r-- | sapi/cli/tests/php_cli_server.inc | 20 | ||||
| -rw-r--r-- | sapi/cli/tests/php_cli_server_012.phpt | 2 | ||||
| -rw-r--r-- | sapi/cli/tests/php_cli_server_014.phpt | 4 | ||||
| -rw-r--r-- | sapi/cli/tests/php_cli_server_016.phpt | 2 | ||||
| -rw-r--r-- | sapi/cli/tests/php_cli_server_017.phpt | 2 |
7 files changed, 204 insertions, 5 deletions
diff --git a/sapi/cli/tests/bug61546.phpt b/sapi/cli/tests/bug61546.phpt new file mode 100644 index 000000000..2cd690f65 --- /dev/null +++ b/sapi/cli/tests/bug61546.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #61546 (functions related to current script failed when chdir() in cli sapi) +--FILE-- +<?php +$php = getenv("TEST_PHP_EXECUTABLE"); +$test_code = <<<PHP +<?php +chdir('..'); +var_dump(get_current_user() != ""); +chdir('..'); +var_dump(getmyinode() != false); +var_dump(getlastmod() != false); +PHP; + +file_put_contents("bug61546_sub.php", $test_code); +system($php . ' -n bug61546_sub.php'); +unlink("bug61546_sub.php"); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/sapi/cli/tests/bug61977.phpt b/sapi/cli/tests/bug61977.phpt new file mode 100644 index 000000000..2f198060f --- /dev/null +++ b/sapi/cli/tests/bug61977.phpt @@ -0,0 +1,157 @@ +--TEST-- +Bug #61977 (Need CLI web-server support for files with .htm & svg extensions) +--SKIPIF-- +<?php +include "skipif.inc"; +?> +--FILE-- +<?php +include "php_cli_server.inc"; +php_cli_server_start('<?php ?>', true); +$doc_root = __DIR__; + +list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); +$port = intval($port)?:80; + +$fp = fsockopen($host, $port, $errno, $errstr, 0.5); +if (!$fp) { + die("connect failed"); +} + +file_put_contents($doc_root . '/foo.html', ''); +if(fwrite($fp, <<<HEADER +GET /foo.html HTTP/1.1 +Host: {$host} + + +HEADER +)) { + while (!feof($fp)) { + $text = fgets($fp); + if (strncasecmp("Content-type:", $text, 13) == 0) { + echo "foo.html => ", $text; + } + } +} +@unlink($doc_root . '/foo.html'); +fclose($fp); + + +$fp = fsockopen($host, $port, $errno, $errstr, 0.5); +if (!$fp) { + die("connect failed"); +} +file_put_contents($doc_root . '/foo.htm', ''); +if(fwrite($fp, <<<HEADER +GET /foo.htm HTTP/1.1 +Host: {$host} + + +HEADER +)) { + while (!feof($fp)) { + $text = fgets($fp); + if (strncasecmp("Content-type:", $text, 13) == 0) { + echo "foo.htm => ", $text; + } + } +} +@unlink($doc_root . '/foo.htm'); +fclose($fp); + + +$fp = fsockopen($host, $port, $errno, $errstr, 0.5); +if (!$fp) { + die("connect failed"); +} +file_put_contents($doc_root . '/foo.svg', ''); +if(fwrite($fp, <<<HEADER +GET /foo.svg HTTP/1.1 +Host: {$host} + + +HEADER +)) { + while (!feof($fp)) { + $text = fgets($fp); + if (strncasecmp("Content-type:", $text, 13) == 0) { + echo "foo.svg => ", $text; + } + } +} +@unlink($doc_root . '/foo.svg'); +fclose($fp); + +$fp = fsockopen($host, $port, $errno, $errstr, 0.5); +if (!$fp) { + die("connect failed"); +} +file_put_contents($doc_root . '/foo.css', ''); +if(fwrite($fp, <<<HEADER +GET /foo.css HTTP/1.1 +Host: {$host} + + +HEADER +)) { + while (!feof($fp)) { + $text = fgets($fp); + if (strncasecmp("Content-type:", $text, 13) == 0) { + echo "foo.css => ", $text; + } + } +} +@unlink($doc_root . '/foo.css'); +fclose($fp); + +$fp = fsockopen($host, $port, $errno, $errstr, 0.5); +if (!$fp) { + die("connect failed"); +} +file_put_contents($doc_root . '/foo.js', ''); +if(fwrite($fp, <<<HEADER +GET /foo.js HTTP/1.1 +Host: {$host} + + +HEADER +)) { + while (!feof($fp)) { + $text = fgets($fp); + if (strncasecmp("Content-type:", $text, 13) == 0) { + echo "foo.js => ", $text; + } + } +} +@unlink($doc_root . '/foo.js'); +fclose($fp); + +$fp = fsockopen($host, $port, $errno, $errstr, 0.5); +if (!$fp) { + die("connect failed"); +} +file_put_contents($doc_root . '/foo.png', ''); +if(fwrite($fp, <<<HEADER +GET /foo.png HTTP/1.1 +Host: {$host} + + +HEADER +)) { + while (!feof($fp)) { + $text = fgets($fp); + if (strncasecmp("Content-type:", $text, 13) == 0) { + echo "foo.png => ", $text; + } + } +} +@unlink($doc_root . '/foo.png'); +fclose($fp); +?> +--EXPECTF-- +foo.html => Content-Type: text/html; charset=UTF-8 +foo.htm => Content-Type: text/html; charset=UTF-8 +foo.svg => Content-Type: image/svg+xml +foo.css => Content-Type: text/css; charset=UTF-8 +foo.js => Content-Type: text/javascript; charset=UTF-8 +foo.png => Content-Type: image/png diff --git a/sapi/cli/tests/php_cli_server.inc b/sapi/cli/tests/php_cli_server.inc index 44ee76ea7..3479cd0bd 100644 --- a/sapi/cli/tests/php_cli_server.inc +++ b/sapi/cli/tests/php_cli_server.inc @@ -1,5 +1,7 @@ <?php -define ("PHP_CLI_SERVER_ADDRESS", "localhost:8964"); +define ("PHP_CLI_SERVER_HOSTNAME", "localhost"); +define ("PHP_CLI_SERVER_PORT", 8964); +define ("PHP_CLI_SERVER_ADDRESS", PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_PORT); function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE) { $php_executable = getenv('TEST_PHP_EXECUTABLE'); @@ -32,6 +34,17 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE) $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root); } + + // note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.' + // it might not be listening yet...need to wait until fsockopen() call returns + $i = 0; + while (($i++ < 5) && !($fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT))) { + usleep(10000); + } + + if ($fp) { + fclose($fp); + } register_shutdown_function( function($handle) use($router) { @@ -40,7 +53,10 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE) }, $handle ); - usleep(50000); + // don't bother sleeping, server is already up + // server can take a variable amount of time to be up, so just sleeping a guessed amount of time + // does not work. this is why tests sometimes pass and sometimes fail. to get a reliable pass + // sleeping doesn't work. } ?> diff --git a/sapi/cli/tests/php_cli_server_012.phpt b/sapi/cli/tests/php_cli_server_012.phpt index a7d908187..9a1e60c48 100644 --- a/sapi/cli/tests/php_cli_server_012.phpt +++ b/sapi/cli/tests/php_cli_server_012.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #60159 (Router returns false, but POST is not passed to requested resource) +Bug #60159 (Router returns false, but POST is not passed to requested resource) --SKIPIF-- <?php include "skipif.inc"; diff --git a/sapi/cli/tests/php_cli_server_014.phpt b/sapi/cli/tests/php_cli_server_014.phpt index 4b56caa70..2eca8706b 100644 --- a/sapi/cli/tests/php_cli_server_014.phpt +++ b/sapi/cli/tests/php_cli_server_014.phpt @@ -13,6 +13,10 @@ list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port)?:80; $output = ''; +// note: select() on Windows (& some other platforms) has historical issues with +// timeouts less than 1000 millis(0.5). it may be better to increase these +// timeouts to 1000 millis(1.0) (fsockopen eventually calls select()). +// see articles like: http://support.microsoft.com/kb/257821 $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); diff --git a/sapi/cli/tests/php_cli_server_016.phpt b/sapi/cli/tests/php_cli_server_016.phpt index 3fd065a1c..f15aff124 100644 --- a/sapi/cli/tests/php_cli_server_016.phpt +++ b/sapi/cli/tests/php_cli_server_016.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #60591 (Memory leak when access a non-exists file) --DESCRIPTION-- -this is a indirect test for bug 50691, since mem leak is reproted in the server side +this is an indirect test for bug 60591, since mem leak is reproted in the server side and require php compiled with --enable-debug --SKIPIF-- <?php diff --git a/sapi/cli/tests/php_cli_server_017.phpt b/sapi/cli/tests/php_cli_server_017.phpt index 6c414a109..73530af48 100644 --- a/sapi/cli/tests/php_cli_server_017.phpt +++ b/sapi/cli/tests/php_cli_server_017.phpt @@ -41,4 +41,4 @@ Connection: close X-Powered-By: %s Content-type: text/html -string(%d) "%s/tests/index.php" +string(%d) "%sindex.php" |
