diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
| commit | 2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch) | |
| tree | 41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /sapi/cli | |
| parent | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff) | |
| download | php-upstream/5.2.2.tar.gz | |
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'sapi/cli')
| -rw-r--r-- | sapi/cli/getopt.c | 40 | ||||
| -rw-r--r-- | sapi/cli/php.1.in | 16 | ||||
| -rw-r--r-- | sapi/cli/php_cli.c | 72 | ||||
| -rw-r--r-- | sapi/cli/php_cli_readline.c | 9 | ||||
| -rw-r--r-- | sapi/cli/php_cli_readline.h | 4 | ||||
| -rw-r--r-- | sapi/cli/php_getopt.h | 4 | ||||
| -rw-r--r-- | sapi/cli/tests/001.phpt | 19 | ||||
| -rw-r--r-- | sapi/cli/tests/002-win32.phpt | 22 | ||||
| -rw-r--r-- | sapi/cli/tests/002.phpt | 22 | ||||
| -rwxr-xr-x | sapi/cli/tests/003-2.phpt | 25 | ||||
| -rw-r--r-- | sapi/cli/tests/003.phpt | 32 | ||||
| -rw-r--r-- | sapi/cli/tests/004.phpt | 34 | ||||
| -rw-r--r-- | sapi/cli/tests/005.phpt | 99 | ||||
| -rw-r--r-- | sapi/cli/tests/006.phpt | 328 | ||||
| -rw-r--r-- | sapi/cli/tests/007.phpt | 52 | ||||
| -rw-r--r-- | sapi/cli/tests/008.phpt | 43 | ||||
| -rw-r--r-- | sapi/cli/tests/009.phpt | 23 | ||||
| -rw-r--r-- | sapi/cli/tests/010-2.phpt | 35 | ||||
| -rw-r--r-- | sapi/cli/tests/010.phpt | 47 | ||||
| -rw-r--r-- | sapi/cli/tests/011.phpt | 58 | ||||
| -rw-r--r-- | sapi/cli/tests/012.phpt | 38 | ||||
| -rw-r--r-- | sapi/cli/tests/013.phpt | 34 | ||||
| -rw-r--r-- | sapi/cli/tests/014.phpt | 44 | ||||
| -rw-r--r-- | sapi/cli/tests/015.phpt | 35 | ||||
| -rw-r--r-- | sapi/cli/tests/skipif.inc | 7 |
25 files changed, 1100 insertions, 42 deletions
diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c index 639eb9bb2..fd665d7d3 100644 --- a/sapi/cli/getopt.c +++ b/sapi/cli/getopt.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: getopt.c,v 1.8.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: getopt.c,v 1.8.2.1.2.5 2007/04/23 11:05:16 tony2001 Exp $ */ #include <stdio.h> #include <string.h> @@ -79,29 +79,35 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta } if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) { /* '--' indicates end of args if not followed by a known long option name */ + if (argv[*optind][2] == '\0') { + (*optind)++; + return(EOF); + } + while (1) { opts_idx++; if (opts[opts_idx].opt_char == '-') { (*optind)++; - return(EOF); + return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err)); } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) { break; } } optchr = 0; - dash = 1; - arg_start = 2 + strlen(opts[opts_idx].opt_name); - } - if (!dash) { - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - if (argv[*optind][optchr] == ':') { dash = 0; - (*optind)++; - return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); + arg_start = 2 + strlen(opts[opts_idx].opt_name); + } else { + if (!dash) { + dash = 1; + optchr = 1; + } + /* Check if the guy tries to do a -: kind of flag */ + if (argv[*optind][optchr] == ':') { + dash = 0; + (*optind)++; + return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); + } + arg_start = 1 + optchr; } if (opts_idx < 0) { while (1) { @@ -115,6 +121,7 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta (*optind)++; } else { optchr++; + arg_start++; } return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) { @@ -138,7 +145,8 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta } return opts[opts_idx].opt_char; } else { - if (arg_start == 2) { + /* multiple options specified as one (exclude long opts) */ + if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) { if (!argv[*optind][optchr+1]) { dash = 0; diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in index 4c86dec40..cb31c832c 100644 --- a/sapi/cli/php.1.in +++ b/sapi/cli/php.1.in @@ -1,4 +1,4 @@ -.TH PHP 1 "2006" "The PHP Group" "Scripting Language" +.TH PHP 1 "2007" "The PHP Group" "Scripting Language" .SH NAME .TP 15 php \- PHP Command Line Interface 'CLI' @@ -294,6 +294,16 @@ Shows information about class .IR name Shows information about extension .B name +.TP +.PD 0 +.B \-\-rextinfo +.IR name +.TP +.PD 1 +.B \-\-ri +.IR name +Shows configuration for extension +.B name .SH FILES .TP 15 .B php\-cli.ini @@ -377,7 +387,7 @@ found at: .SH AUTHORS The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski. .P -Additional work for the CLI sapi was done by Edin Kadribasic and Marcus Boerger. +Additional work for the CLI sapi was done by Edin Kadribasic, Marcus Boerger and Johannes Schlueter. .P A List of active developers can be found here: .PD 0 @@ -390,7 +400,7 @@ contributors all around the world. .SH VERSION INFORMATION This manpage describes \fBphp\fP, version @PHP_VERSION@. .SH COPYRIGHT -Copyright \(co 1997\-2006 The PHP Group +Copyright \(co 1997\-2007 The PHP Group .LP This source file is subject to version 3.01 of the PHP license, that is bundled with this package in the file LICENSE, and is diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index cb094a07b..e91dbfa2f 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli.c,v 1.129.2.13.2.10 2006/09/22 17:41:09 iliaa Exp $ */ +/* $Id: php_cli.c,v 1.129.2.13.2.18 2007/04/25 09:56:29 bjori Exp $ */ #include "php.h" #include "php_globals.h" @@ -105,16 +105,16 @@ #define PHP_MODE_REFLECTION_FUNCTION 8 #define PHP_MODE_REFLECTION_CLASS 9 #define PHP_MODE_REFLECTION_EXTENSION 10 +#define PHP_MODE_REFLECTION_EXT_INFO 11 #define HARDCODED_INI \ "html_errors=0\n" \ "register_argc_argv=1\n" \ "implicit_flush=1\n" \ "output_buffering=0\n" \ - "max_execution_time=0\n" \ + "max_execution_time=0\n" \ "max_input_time=-1\n" - static char *php_optarg = NULL; static int php_optind = 1; #if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) @@ -153,6 +153,8 @@ static const opt_struct OPTIONS[] = { {11, 1, "rclass"}, {12, 1, "re"}, {12, 1, "rextension"}, + {13, 1, "ri"}, + {13, 1, "rextinfo"}, #endif {'-', 0, NULL} /* end of args */ }; @@ -450,6 +452,7 @@ static void php_cli_usage(char *argv0) " --rf <name> Show information about function <name>.\n" " --rc <name> Show information about class <name>.\n" " --re <name> Show information about extension <name>.\n" + " --ri <name> Show configuration for extension <name>.\n" "\n" #endif , prog, prog, prog, prog, prog, prog); @@ -474,9 +477,21 @@ static void cli_register_file_handles(TSRMLS_D) s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err); if (s_in==NULL || s_out==NULL || s_err==NULL) { + FREE_ZVAL(zin); + FREE_ZVAL(zout); + FREE_ZVAL(zerr); + if (s_in) php_stream_close(s_in); + if (s_out) php_stream_close(s_out); + if (s_err) php_stream_close(s_err); return; } - + +#if PHP_DEBUG + /* do not close stdout and stderr */ + s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE; + s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE; +#endif + s_in_process = s_in; php_stream_to_zval(s_in, zin); @@ -617,8 +632,8 @@ int main(int argc, char *argv[]) tsrm_startup(1, 1, 0, NULL); #endif - cli_sapi_module.php_ini_path_override = NULL; cli_sapi_module.ini_defaults = sapi_cli_ini_defaults; + cli_sapi_module.php_ini_path_override = NULL; cli_sapi_module.phpinfo_as_text = 1; sapi_startup(&cli_sapi_module); @@ -636,13 +651,16 @@ int main(int argc, char *argv[]) while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0))!=-1) { switch (c) { - case 'c': - cli_sapi_module.php_ini_path_override = strdup(php_optarg); - break; - case 'n': - cli_sapi_module.php_ini_ignore = 1; - break; - case 'd': { + case 'c': + if (cli_sapi_module.php_ini_path_override) { + free(cli_sapi_module.php_ini_path_override); + } + cli_sapi_module.php_ini_path_override = strdup(php_optarg); + break; + case 'n': + cli_sapi_module.php_ini_ignore = 1; + break; + case 'd': { /* define ini entries on command line */ int len = strlen(php_optarg); char *val; @@ -689,7 +707,7 @@ int main(int argc, char *argv[]) #endif /* startup after we get the above ini override se we get things right */ - if (php_module_startup(&cli_sapi_module, NULL, 0)==FAILURE) { + if (cli_sapi_module.startup(&cli_sapi_module)==FAILURE) { /* there is no way to see if we must call zend_ini_deactivate() * since we cannot check if EG(ini_directives) has been initialised * because the executor's constructor does not set initialize it. @@ -754,7 +772,7 @@ int main(int argc, char *argv[]) } request_started = 1; - php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2006 The PHP Group\n%s", + php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, #if ZEND_DEBUG && defined(HAVE_GCOV) "(DEBUG GCOV)", @@ -941,6 +959,10 @@ int main(int argc, char *argv[]) behavior=PHP_MODE_REFLECTION_EXTENSION; reflection_what = php_optarg; break; + case 13: + behavior=PHP_MODE_REFLECTION_EXT_INFO; + reflection_what = php_optarg; + break; #endif default: break; @@ -1248,6 +1270,26 @@ int main(int argc, char *argv[]) break; } + case PHP_MODE_REFLECTION_EXT_INFO: + { + int len = strlen(reflection_what); + char *lcname = zend_str_tolower_dup(reflection_what, len); + zend_module_entry *module; + + if (zend_hash_find(&module_registry, lcname, len+1, (void**)&module) == FAILURE) { + if (!strcmp(reflection_what, "main")) { + display_ini_entries(NULL); + } else { + zend_printf("Extension '%s' not present.\n", reflection_what); + exit_status = 1; + } + } else { + php_info_print_module(module TSRMLS_CC); + } + + efree(lcname); + break; + } #endif /* reflection */ } } diff --git a/sapi/cli/php_cli_readline.c b/sapi/cli/php_cli_readline.c index 6cca22436..06903a7db 100644 --- a/sapi/cli/php_cli_readline.c +++ b/sapi/cli/php_cli_readline.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli_readline.c,v 1.3.2.5 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: php_cli_readline.c,v 1.3.2.5.2.2 2007/02/24 02:17:28 helly Exp $ */ #include "php.h" @@ -418,9 +418,10 @@ TODO: efree(class_name); } if (pce && retval) { - char *tmp = malloc(class_name_len + 2 + strlen(retval) + 1); + int len = class_name_len + 2 + strlen(retval) + 1; + char *tmp = malloc(len); - sprintf(tmp, "%s::%s", (*pce)->name, retval); + snprintf(tmp, len, "%s::%s", (*pce)->name, retval); free(retval); retval = tmp; } diff --git a/sapi/cli/php_cli_readline.h b/sapi/cli/php_cli_readline.h index 58b99398e..f27525faa 100644 --- a/sapi/cli/php_cli_readline.h +++ b/sapi/cli/php_cli_readline.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli_readline.h,v 1.2.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: php_cli_readline.h,v 1.2.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #include "php.h" diff --git a/sapi/cli/php_getopt.h b/sapi/cli/php_getopt.h index 8d38e2803..24ac5c3f3 100644 --- a/sapi/cli/php_getopt.h +++ b/sapi/cli/php_getopt.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_getopt.h,v 1.7.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: php_getopt.h,v 1.7.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #include "php.h" diff --git a/sapi/cli/tests/001.phpt b/sapi/cli/tests/001.phpt new file mode 100644 index 000000000..6fbd608a6 --- /dev/null +++ b/sapi/cli/tests/001.phpt @@ -0,0 +1,19 @@ +--TEST-- +version string +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n -v`); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "PHP %s (cli) (built: %s)%s +Copyright (c) 1997-20%d The PHP Group +Zend Engine v%s, Copyright (c) 1998-20%d Zend Technologies +" +Done diff --git a/sapi/cli/tests/002-win32.phpt b/sapi/cli/tests/002-win32.phpt new file mode 100644 index 000000000..ca0e66ddc --- /dev/null +++ b/sapi/cli/tests/002-win32.phpt @@ -0,0 +1,22 @@ +--TEST-- +running code with -r +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) != 'WIN') { + die ("skip only for Windows"); +} +?> +--FILE-- +<?php + +$php = $_ENV['TEST_PHP_EXECUTABLE']; + +var_dump(`$php -n -r "var_dump('hello');"`); + +echo "Done\n"; +?> +--EXPECTF-- +string(18) "string(5) "hello" +" +Done diff --git a/sapi/cli/tests/002.phpt b/sapi/cli/tests/002.phpt new file mode 100644 index 000000000..be2b6331b --- /dev/null +++ b/sapi/cli/tests/002.phpt @@ -0,0 +1,22 @@ +--TEST-- +running code with -r +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n -r 'var_dump("hello");'`); + +echo "Done\n"; +?> +--EXPECTF-- +string(18) "string(5) "hello" +" +Done diff --git a/sapi/cli/tests/003-2.phpt b/sapi/cli/tests/003-2.phpt new file mode 100755 index 000000000..2ed9b07db --- /dev/null +++ b/sapi/cli/tests/003-2.phpt @@ -0,0 +1,25 @@ +--TEST-- +defining INI options with -d (as 2nd arg) +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`"$php" -nd max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'`); +var_dump(`"$php" -nd max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'`); + +?> +===DONE=== +--EXPECTF-- +string(16) "string(3) "111" +" +string(16) "string(3) "500" +" +===DONE=== diff --git a/sapi/cli/tests/003.phpt b/sapi/cli/tests/003.phpt new file mode 100644 index 000000000..d62360e1f --- /dev/null +++ b/sapi/cli/tests/003.phpt @@ -0,0 +1,32 @@ +--TEST-- +defining INI options with -d +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n -d max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'`); +var_dump(`$php -n -d max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'`); +var_dump(`$php -n -d max_execution_time=500 -d max_execution_time=555 -r 'var_dump(ini_get("max_execution_time"));'`); +var_dump(`$php -n -d upload_tmp_dir=/test/path -d max_execution_time=555 -r 'var_dump(ini_get("max_execution_time")); var_dump(ini_get("upload_tmp_dir"));'`); + +echo "Done\n"; +?> +--EXPECTF-- +string(16) "string(3) "111" +" +string(16) "string(3) "500" +" +string(16) "string(3) "555" +" +string(40) "string(3) "555" +string(10) "/test/path" +" +Done diff --git a/sapi/cli/tests/004.phpt b/sapi/cli/tests/004.phpt new file mode 100644 index 000000000..24c8d31c9 --- /dev/null +++ b/sapi/cli/tests/004.phpt @@ -0,0 +1,34 @@ +--TEST-- +show information about function +--SKIPIF-- +<?php +include "skipif.inc"; +if (!extension_loaded("reflection")) { + die("skip"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n --rf unknown`); +var_dump(`$php -n --rf echo`); +var_dump(`$php -n --rf phpinfo`); + +echo "Done\n"; +?> +--EXPECTF-- +string(45) "Exception: Function unknown() does not exist +" +string(42) "Exception: Function echo() does not exist +" +string(110) "Function [ <internal> function phpinfo ] { + + - Parameters [1] { + Parameter #0 [ <optional> $what ] + } +} + +" +Done diff --git a/sapi/cli/tests/005.phpt b/sapi/cli/tests/005.phpt new file mode 100644 index 000000000..0b38bba76 --- /dev/null +++ b/sapi/cli/tests/005.phpt @@ -0,0 +1,99 @@ +--TEST-- +show information about class +--SKIPIF-- +<?php +include "skipif.inc"; +if (!extension_loaded("reflection")) { + die("skip"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n --rc unknown`); +var_dump(`$php -n --rc stdclass`); +var_dump(`$php -n --rc exception`); + +echo "Done\n"; +?> +--EXPECTF-- +string(40) "Exception: Class unknown does not exist +" +string(178) "Class [ <internal> class stdClass ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [0] { + } +} + +" +string(1141) "Class [ <internal> class Exception ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [6] { + Property [ <default> protected $message ] + Property [ <default> private $string ] + Property [ <default> protected $code ] + Property [ <default> protected $file ] + Property [ <default> protected $line ] + Property [ <default> private $trace ] + } + + - Methods [9] { + Method [ <internal> final private method __clone ] { + } + + Method [ <internal, ctor> public method __construct ] { + + - Parameters [2] { + Parameter #0 [ <optional> $message ] + Parameter #1 [ <optional> $code ] + } + } + + Method [ <internal> final public method getMessage ] { + } + + Method [ <internal> final public method getCode ] { + } + + Method [ <internal> final public method getFile ] { + } + + Method [ <internal> final public method getLine ] { + } + + Method [ <internal> final public method getTrace ] { + } + + Method [ <internal> final public method getTraceAsString ] { + } + + Method [ <internal> public method __toString ] { + } + } +} + +" +Done diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt new file mode 100644 index 000000000..8ce82b3b7 --- /dev/null +++ b/sapi/cli/tests/006.phpt @@ -0,0 +1,328 @@ +--TEST-- +show information about extension +--SKIPIF-- +<?php +include "skipif.inc"; +if (!extension_loaded("reflection")) { + die("skip"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n --re unknown`); +var_dump(`$php -n --re ""`); +var_dump(`$php -n --re date`); + +echo "Done\n"; +?> +--EXPECTF-- +string(44) "Exception: Extension unknown does not exist +" +string(37) "Exception: Extension does not exist +" +string(%d) "Extension [ <persistent> extension #%d date version %s ] { + + - Dependencies { + Dependency [ session (Optional) ] + } + + - INI { + Entry [ date.timezone <ALL> ] + Current = '' + } + Entry [ date.default_latitude <ALL> ] + Current = '%s' + } + Entry [ date.default_longitude <ALL> ] + Current = '%s' + } + Entry [ date.sunset_zenith <ALL> ] + Current = '%s' + } + Entry [ date.sunrise_zenith <ALL> ] + Current = '%s' + } + } + + - Constants [14] { + Constant [ string DATE_ATOM ] { Y-m-d\TH:i:sP } + Constant [ string DATE_COOKIE ] { l, d-M-y H:i:s T } + Constant [ string DATE_ISO8601 ] { Y-m-d\TH:i:sO } + Constant [ string DATE_RFC822 ] { D, d M y H:i:s O } + Constant [ string DATE_RFC850 ] { l, d-M-y H:i:s T } + Constant [ string DATE_RFC1036 ] { D, d M y H:i:s O } + Constant [ string DATE_RFC1123 ] { D, d M Y H:i:s O } + Constant [ string DATE_RFC2822 ] { D, d M Y H:i:s O } + Constant [ string DATE_RFC3339 ] { Y-m-d\TH:i:sP } + Constant [ string DATE_RSS ] { D, d M Y H:i:s O } + Constant [ string DATE_W3C ] { Y-m-d\TH:i:sP } + Constant [ integer SUNFUNCS_RET_TIMESTAMP ] { 0 } + Constant [ integer SUNFUNCS_RET_STRING ] { 1 } + Constant [ integer SUNFUNCS_RET_DOUBLE ] { 2 } + } + + - Functions { + Function [ <internal> function strtotime ] { + + - Parameters [2] { + Parameter #0 [ <required> $time ] + Parameter #1 [ <optional> $now ] + } + } + Function [ <internal> function date ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function idate ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function gmdate ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function mktime ] { + + - Parameters [6] { + Parameter #0 [ <optional> $hour ] + Parameter #1 [ <optional> $min ] + Parameter #2 [ <optional> $sec ] + Parameter #3 [ <optional> $mon ] + Parameter #4 [ <optional> $day ] + Parameter #5 [ <optional> $year ] + } + } + Function [ <internal> function gmmktime ] { + + - Parameters [6] { + Parameter #0 [ <optional> $hour ] + Parameter #1 [ <optional> $min ] + Parameter #2 [ <optional> $sec ] + Parameter #3 [ <optional> $mon ] + Parameter #4 [ <optional> $day ] + Parameter #5 [ <optional> $year ] + } + } + Function [ <internal> function checkdate ] { + + - Parameters [3] { + Parameter #0 [ <required> $month ] + Parameter #1 [ <required> $day ] + Parameter #2 [ <required> $year ] + } + } + Function [ <internal> function strftime ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function gmstrftime ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function time ] { + + - Parameters [0] { + } + } + Function [ <internal> function localtime ] { + + - Parameters [2] { + Parameter #0 [ <optional> $timestamp ] + Parameter #1 [ <optional> $associative_array ] + } + } + Function [ <internal> function getdate ] { + + - Parameters [1] { + Parameter #0 [ <optional> $timestamp ] + } + } + Function [ <internal> function date_create ] { + } + Function [ <internal> function date_parse ] { + } + Function [ <internal> function date_format ] { + } + Function [ <internal> function date_modify ] { + } + Function [ <internal> function date_timezone_get ] { + } + Function [ <internal> function date_timezone_set ] { + } + Function [ <internal> function date_offset_get ] { + } + Function [ <internal> function date_time_set ] { + } + Function [ <internal> function date_date_set ] { + } + Function [ <internal> function date_isodate_set ] { + } + Function [ <internal> function timezone_open ] { + } + Function [ <internal> function timezone_name_get ] { + } + Function [ <internal> function timezone_name_from_abbr ] { + } + Function [ <internal> function timezone_offset_get ] { + } + Function [ <internal> function timezone_transitions_get ] { + } + Function [ <internal> function timezone_identifiers_list ] { + } + Function [ <internal> function timezone_abbreviations_list ] { + } + Function [ <internal> function date_default_timezone_set ] { + + - Parameters [1] { + Parameter #0 [ <required> $timezone_identifier ] + } + } + Function [ <internal> function date_default_timezone_get ] { + + - Parameters [0] { + } + } + Function [ <internal> function date_sunrise ] { + + - Parameters [6] { + Parameter #0 [ <required> $time ] + Parameter #1 [ <optional> $format ] + Parameter #2 [ <optional> $latitude ] + Parameter #3 [ <optional> $longitude ] + Parameter #4 [ <optional> $zenith ] + Parameter #5 [ <optional> $gmt_offset ] + } + } + Function [ <internal> function date_sunset ] { + + - Parameters [6] { + Parameter #0 [ <required> $time ] + Parameter #1 [ <optional> $format ] + Parameter #2 [ <optional> $latitude ] + Parameter #3 [ <optional> $longitude ] + Parameter #4 [ <optional> $zenith ] + Parameter #5 [ <optional> $gmt_offset ] + } + } + Function [ <internal> function date_sun_info ] { + + - Parameters [3] { + Parameter #0 [ <required> $time ] + Parameter #1 [ <required> $latitude ] + Parameter #2 [ <required> $longitude ] + } + } + } + + - Classes [2] { + Class [ <internal:date> class DateTime ] { + + - Constants [11] { + Constant [ string ATOM ] { Y-m-d\TH:i:sP } + Constant [ string COOKIE ] { l, d-M-y H:i:s T } + Constant [ string ISO8601 ] { Y-m-d\TH:i:sO } + Constant [ string RFC822 ] { D, d M y H:i:s O } + Constant [ string RFC850 ] { l, d-M-y H:i:s T } + Constant [ string RFC1036 ] { D, d M y H:i:s O } + Constant [ string RFC1123 ] { D, d M Y H:i:s O } + Constant [ string RFC2822 ] { D, d M Y H:i:s O } + Constant [ string RFC3339 ] { Y-m-d\TH:i:sP } + Constant [ string RSS ] { D, d M Y H:i:s O } + Constant [ string W3C ] { Y-m-d\TH:i:sP } + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [9] { + Method [ <internal, ctor> public method __construct ] { + } + + Method [ <internal> public method format ] { + } + + Method [ <internal> public method modify ] { + } + + Method [ <internal> public method getTimezone ] { + } + + Method [ <internal> public method setTimezone ] { + } + + Method [ <internal> public method getOffset ] { + } + + Method [ <internal> public method setTime ] { + } + + Method [ <internal> public method setDate ] { + } + + Method [ <internal> public method setISODate ] { + } + } + } + + Class [ <internal:date> class DateTimeZone ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [2] { + Method [ <internal> static public method listAbbreviations ] { + } + + Method [ <internal> static public method listIdentifiers ] { + } + } + + - Properties [0] { + } + + - Methods [4] { + Method [ <internal, ctor> public method __construct ] { + } + + Method [ <internal> public method getName ] { + } + + Method [ <internal> public method getOffset ] { + } + + Method [ <internal> public method getTransitions ] { + } + } + } + } +} + +" +Done diff --git a/sapi/cli/tests/007.phpt b/sapi/cli/tests/007.phpt new file mode 100644 index 000000000..12fddee01 --- /dev/null +++ b/sapi/cli/tests/007.phpt @@ -0,0 +1,52 @@ +--TEST-- +strip comments and whitespace with -w +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__).'/007.test.php'; +$code =' +<?php +/* some test script */ + +class test { /* {{{ */ + public $var = "test"; //test var +#perl style comment + private $pri; /* private attr */ + + function foo(/* void */) { + } +} +/* }}} */ + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`$php -n -w "$filename"`); +var_dump(`$php -n -w "wrong"`); +var_dump(`echo "<?php /* comment */ class test {\n // comment \n function foo() {} } ?>" | $php -n -w`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(81) " +<?php + class test { public $var = "test"; private $pri; function foo() { } } ?> +" +Could not open input file: wrong +NULL +string(43) "<?php class test { function foo() {} } ?> +" +Done diff --git a/sapi/cli/tests/008.phpt b/sapi/cli/tests/008.phpt new file mode 100644 index 000000000..a83304309 --- /dev/null +++ b/sapi/cli/tests/008.phpt @@ -0,0 +1,43 @@ +--TEST-- +execute a file with -f +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__).'/008.test.php'; +$code =' +<?php + +class test { + private $pri; +} + +var_dump(test::$pri); +?> +'; + +file_put_contents($filename, $code); + +var_dump(`$php -n -f "$filename"`); +var_dump(`$php -n -f "wrong"`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) " + +Fatal error: Cannot access private property test::$pri in %s on line %d +" +Could not open input file: wrong +NULL +Done diff --git a/sapi/cli/tests/009.phpt b/sapi/cli/tests/009.phpt new file mode 100644 index 000000000..c0bb319f7 --- /dev/null +++ b/sapi/cli/tests/009.phpt @@ -0,0 +1,23 @@ +--TEST-- +using invalid combinations of cmdline options +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n -c -r "echo hello;"`); +var_dump(`$php -n -a -r "echo hello;"`); +var_dump(`$php -n -r "echo hello;" -a`); + +echo "Done\n"; +?> +--EXPECTF-- +You cannot use both -n and -c switch. Use -h for help. +NULL +Either execute direct code, process stdin or use a file. +NULL +Either execute direct code, process stdin or use a file. +NULL +Done diff --git a/sapi/cli/tests/010-2.phpt b/sapi/cli/tests/010-2.phpt new file mode 100644 index 000000000..bd33d2cc9 --- /dev/null +++ b/sapi/cli/tests/010-2.phpt @@ -0,0 +1,35 @@ +--TEST-- +executing a code with -R +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename_txt = dirname(__FILE__)."/010.test.txt"; + +$txt = ' +test +hello +'; + +file_put_contents($filename_txt, $txt); + +var_dump(`cat "$filename_txt" | "$php" -n -R "var_dump(1);"`); + +@unlink($filename_txt); + +echo "Done\n"; +?> +--EXPECTF-- +string(21) "int(1) +int(1) +int(1) +" +Done diff --git a/sapi/cli/tests/010.phpt b/sapi/cli/tests/010.phpt new file mode 100644 index 000000000..e465e3797 --- /dev/null +++ b/sapi/cli/tests/010.phpt @@ -0,0 +1,47 @@ +--TEST-- +executing a file with -F +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__)."/010.test.php"; +$filename_txt = dirname(__FILE__)."/010.test.txt"; + +$code = ' +<?php +var_dump(fread(STDIN, 10)); +?> +'; + +file_put_contents($filename, $code); + +$txt = ' +test +hello +'; + +file_put_contents($filename_txt, $txt); + +var_dump(`cat "$filename_txt" | "$php" -n -F "$filename"`); + +@unlink($filename); +@unlink($filename_txt); + +echo "Done\n"; +?> +--EXPECTF-- +string(39) " +string(10) "test +hello" + +string(0) "" +" +Done diff --git a/sapi/cli/tests/011.phpt b/sapi/cli/tests/011.phpt new file mode 100644 index 000000000..ef49666d3 --- /dev/null +++ b/sapi/cli/tests/011.phpt @@ -0,0 +1,58 @@ +--TEST-- +syntax check +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__)."/011.test.php"; + +$code = ' +<?php + +$test = "var"; + +class test { + private $var; +} + +echo test::$var; + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -l $filename`); +var_dump(`"$php" -n -l some.unknown`); + +$code = ' +<?php + +class test + private $var; +} + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -l $filename`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "No syntax errors detected in %s011.test.php +" +Could not open input file: some.unknown +NULL +string(%d) " +Parse error: %s expecting %s{%s in %s on line %d +Errors parsing %s011.test.php +" +Done diff --git a/sapi/cli/tests/012.phpt b/sapi/cli/tests/012.phpt new file mode 100644 index 000000000..137e0bd78 --- /dev/null +++ b/sapi/cli/tests/012.phpt @@ -0,0 +1,38 @@ +--TEST-- +invalid arguments and error messages +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`"$php" -n -F some.php -F some.php`); +var_dump(`"$php" -n -F some.php -R some.php`); +var_dump(`"$php" -n -R some.php -F some.php`); +var_dump(`"$php" -n -R some.php -R some.php`); +var_dump(`"$php" -n -f some.php -f some.php`); +var_dump(`"$php" -n -B '' -B ''`); +var_dump(`"$php" -n -E '' -E ''`); +var_dump(`"$php" -n -r '' -r ''`); + +echo "Done\n"; +?> +--EXPECTF-- +You can use -R or -F only once. +NULL +You can use -R or -F only once. +NULL +You can use -R or -F only once. +NULL +You can use -R or -F only once. +NULL +You can use -f only once. +NULL +You can use -B only once. +NULL +You can use -E only once. +NULL +You can use -r only once. +NULL +Done diff --git a/sapi/cli/tests/013.phpt b/sapi/cli/tests/013.phpt new file mode 100644 index 000000000..99bfe5e7b --- /dev/null +++ b/sapi/cli/tests/013.phpt @@ -0,0 +1,34 @@ +--TEST-- +running PHP code before and after processing input lines with -B and -E +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename_txt = dirname(__FILE__)."/013.test.txt"; +file_put_contents($filename_txt, "test\nfile\ncontents\n"); + +var_dump(`cat "$filename_txt" | "$php" -n -B 'var_dump("start");'`); +var_dump(`cat "$filename_txt" | "$php" -n -E 'var_dump("end");'`); +var_dump(`cat "$filename_txt" | "$php" -n -B 'var_dump("start");' -E 'var_dump("end");'`); + +@unlink($filename_txt); + +echo "Done\n"; +?> +--EXPECTF-- +string(18) "string(5) "start" +" +string(16) "string(3) "end" +" +string(34) "string(5) "start" +string(3) "end" +" +Done diff --git a/sapi/cli/tests/014.phpt b/sapi/cli/tests/014.phpt new file mode 100644 index 000000000..b20478a03 --- /dev/null +++ b/sapi/cli/tests/014.phpt @@ -0,0 +1,44 @@ +--TEST-- +syntax highlighting +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__)."/014.test.php"; +$code = ' +<?php +$test = "var"; //var +/* test class */ +class test { + private $var = array(); + + public static function foo(Test $arg) { + echo "hello"; + var_dump($this); + } +} + +$o = new test; +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -s $filename`); +var_dump(`"$php" -n -s unknown`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(1478) "<code><span style="color: #000000"> +<br /><span style="color: #0000BB"><?php<br />$test </span><span style="color: #007700">= </span><span style="color: #DD0000">"var"</span><span style="color: #007700">; </span><span style="color: #FF8000">//var<br />/* test class */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">test </span><span style="color: #007700">{<br /> private </span><span style="color: #0000BB">$var </span><span style="color: #007700">= array();<br /><br /> public static function </span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">Test $arg</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">);<br /> }<br />}<br /><br /></span><span style="color: #0000BB">$o </span><span style="color: #007700">= new </span><span style="color: #0000BB">test</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?><br /></span> +</span> +</code>" +Could not open input file: unknown +NULL +Done diff --git a/sapi/cli/tests/015.phpt b/sapi/cli/tests/015.phpt new file mode 100644 index 000000000..be501d471 --- /dev/null +++ b/sapi/cli/tests/015.phpt @@ -0,0 +1,35 @@ +--TEST-- +CLI long options +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + + +echo `"$php" --version | grep built:`; +echo `echo "<?php print_r(\\\$argv);" | "$php" -- foo bar baz`, "\n"; +echo `"$php" --version foo bar baz | grep built:`; +echo `"$php" --notexisting foo bar baz | grep Usage:`; + +echo "Done\n"; +?> +--EXPECTF-- +PHP %d.%d.%d%s(cli) (built: %s)%s +Array +( + [0] => - + [1] => foo + [2] => bar + [3] => baz +) + +PHP %d.%d.%d%s(cli) (built: %s)%s +Usage: php [options] [-f] <file> [--] [args...] +Done diff --git a/sapi/cli/tests/skipif.inc b/sapi/cli/tests/skipif.inc new file mode 100644 index 000000000..79e6c9100 --- /dev/null +++ b/sapi/cli/tests/skipif.inc @@ -0,0 +1,7 @@ +<?php + +if (php_sapi_name() != "cli") { + die("skip CLI only"); +} + +?> |
