From 158ad3ee2ff66292e2a9fd9dab587e1c1a3e761f Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Fri, 24 Nov 2006 13:33:38 +0000 Subject: add tests for CLI --- sapi/cli/tests/001.phpt | 19 +++ sapi/cli/tests/002-win32.phpt | 22 +++ sapi/cli/tests/002.phpt | 22 +++ sapi/cli/tests/003.phpt | 32 +++++ sapi/cli/tests/004.phpt | 29 ++++ sapi/cli/tests/005.phpt | 94 ++++++++++++ sapi/cli/tests/006.phpt | 323 ++++++++++++++++++++++++++++++++++++++++++ sapi/cli/tests/007.phpt | 52 +++++++ sapi/cli/tests/008.phpt | 43 ++++++ sapi/cli/tests/009.phpt | 23 +++ sapi/cli/tests/010-2.phpt | 35 +++++ sapi/cli/tests/010.phpt | 47 ++++++ sapi/cli/tests/011.phpt | 58 ++++++++ sapi/cli/tests/012.phpt | 38 +++++ sapi/cli/tests/013.phpt | 34 +++++ sapi/cli/tests/014.phpt | 44 ++++++ sapi/cli/tests/skipif.inc | 7 + 17 files changed, 922 insertions(+) create mode 100644 sapi/cli/tests/001.phpt create mode 100644 sapi/cli/tests/002-win32.phpt create mode 100644 sapi/cli/tests/002.phpt create mode 100644 sapi/cli/tests/003.phpt create mode 100644 sapi/cli/tests/004.phpt create mode 100644 sapi/cli/tests/005.phpt create mode 100644 sapi/cli/tests/006.phpt create mode 100644 sapi/cli/tests/007.phpt create mode 100644 sapi/cli/tests/008.phpt create mode 100644 sapi/cli/tests/009.phpt create mode 100644 sapi/cli/tests/010-2.phpt create mode 100644 sapi/cli/tests/010.phpt create mode 100644 sapi/cli/tests/011.phpt create mode 100644 sapi/cli/tests/012.phpt create mode 100644 sapi/cli/tests/013.phpt create mode 100644 sapi/cli/tests/014.phpt create mode 100644 sapi/cli/tests/skipif.inc (limited to 'sapi') diff --git a/sapi/cli/tests/001.phpt b/sapi/cli/tests/001.phpt new file mode 100644 index 0000000000..0adb5c6788 --- /dev/null +++ b/sapi/cli/tests/001.phpt @@ -0,0 +1,19 @@ +--TEST-- +version string +--SKIPIF-- + +--FILE-- + +--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 0000000000..36d60adbf2 --- /dev/null +++ b/sapi/cli/tests/002-win32.phpt @@ -0,0 +1,22 @@ +--TEST-- +running code with -r +--SKIPIF-- + +--FILE-- + +--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 0000000000..04c81d2fb7 --- /dev/null +++ b/sapi/cli/tests/002.phpt @@ -0,0 +1,22 @@ +--TEST-- +running code with -r +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(18) "string(5) "hello" +" +Done diff --git a/sapi/cli/tests/003.phpt b/sapi/cli/tests/003.phpt new file mode 100644 index 0000000000..c11bc1d221 --- /dev/null +++ b/sapi/cli/tests/003.phpt @@ -0,0 +1,32 @@ +--TEST-- +defining INI options with -d +--SKIPIF-- + +--FILE-- + +--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 0000000000..1a40e2cb1c --- /dev/null +++ b/sapi/cli/tests/004.phpt @@ -0,0 +1,29 @@ +--TEST-- +show information about function +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(45) "Exception: Function unknown() does not exist +" +string(42) "Exception: Function echo() does not exist +" +string(117) "Function [ public function phpinfo ] { + + - Parameters [1] { + Parameter #0 [ $what ] + } +} + +" +Done diff --git a/sapi/cli/tests/005.phpt b/sapi/cli/tests/005.phpt new file mode 100644 index 0000000000..bfc29516f7 --- /dev/null +++ b/sapi/cli/tests/005.phpt @@ -0,0 +1,94 @@ +--TEST-- +show information about class +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(40) "Exception: Class unknown does not exist +" +string(178) "Class [ class stdClass ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [0] { + } +} + +" +string(1141) "Class [ class Exception ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [6] { + Property [ protected $message ] + Property [ private $string ] + Property [ protected $code ] + Property [ protected $file ] + Property [ protected $line ] + Property [ private $trace ] + } + + - Methods [9] { + Method [ final private method __clone ] { + } + + Method [ public method __construct ] { + + - Parameters [2] { + Parameter #0 [ $message ] + Parameter #1 [ $code ] + } + } + + Method [ final public method getMessage ] { + } + + Method [ final public method getCode ] { + } + + Method [ final public method getFile ] { + } + + Method [ final public method getLine ] { + } + + Method [ final public method getTrace ] { + } + + Method [ final public method getTraceAsString ] { + } + + Method [ public method __toString ] { + } + } +} + +" +Done diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt new file mode 100644 index 0000000000..6e830183c6 --- /dev/null +++ b/sapi/cli/tests/006.phpt @@ -0,0 +1,323 @@ +--TEST-- +show information about extension +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(44) "Exception: Extension unknown does not exist +" +string(37) "Exception: Extension does not exist +" +string(%d) "Extension [ extension #%d date version %s ] { + + - Dependencies { + Dependency [ session (Optional) ] + } + + - INI { + Entry [ date.timezone ] + Current = '' + } + Entry [ date.default_latitude ] + Current = '%s' + } + Entry [ date.default_longitude ] + Current = '%s' + } + Entry [ date.sunset_zenith ] + Current = '%s' + } + Entry [ date.sunrise_zenith ] + 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 [ public function strtotime ] { + + - Parameters [2] { + Parameter #0 [ $time ] + Parameter #1 [ $now ] + } + } + Function [ public function date ] { + + - Parameters [2] { + Parameter #0 [ $format ] + Parameter #1 [ $timestamp ] + } + } + Function [ public function idate ] { + + - Parameters [2] { + Parameter #0 [ $format ] + Parameter #1 [ $timestamp ] + } + } + Function [ public function gmdate ] { + + - Parameters [2] { + Parameter #0 [ $format ] + Parameter #1 [ $timestamp ] + } + } + Function [ public function mktime ] { + + - Parameters [6] { + Parameter #0 [ $hour ] + Parameter #1 [ $min ] + Parameter #2 [ $sec ] + Parameter #3 [ $mon ] + Parameter #4 [ $day ] + Parameter #5 [ $year ] + } + } + Function [ public function gmmktime ] { + + - Parameters [6] { + Parameter #0 [ $hour ] + Parameter #1 [ $min ] + Parameter #2 [ $sec ] + Parameter #3 [ $mon ] + Parameter #4 [ $day ] + Parameter #5 [ $year ] + } + } + Function [ public function checkdate ] { + + - Parameters [3] { + Parameter #0 [ $month ] + Parameter #1 [ $day ] + Parameter #2 [ $year ] + } + } + Function [ public function strftime ] { + + - Parameters [2] { + Parameter #0 [ $format ] + Parameter #1 [ $timestamp ] + } + } + Function [ public function gmstrftime ] { + + - Parameters [2] { + Parameter #0 [ $format ] + Parameter #1 [ $timestamp ] + } + } + Function [ public function time ] { + + - Parameters [0] { + } + } + Function [ public function localtime ] { + + - Parameters [2] { + Parameter #0 [ $timestamp ] + Parameter #1 [ $associative_array ] + } + } + Function [ public function getdate ] { + + - Parameters [1] { + Parameter #0 [ $timestamp ] + } + } + Function [ public function date_create ] { + } + Function [ public function date_parse ] { + } + Function [ public function date_format ] { + } + Function [ public function date_modify ] { + } + Function [ public function date_timezone_get ] { + } + Function [ public function date_timezone_set ] { + } + Function [ public function date_offset_get ] { + } + Function [ public function date_time_set ] { + } + Function [ public function date_date_set ] { + } + Function [ public function date_isodate_set ] { + } + Function [ public function timezone_open ] { + } + Function [ public function timezone_name_get ] { + } + Function [ public function timezone_name_from_abbr ] { + } + Function [ public function timezone_offset_get ] { + } + Function [ public function timezone_transitions_get ] { + } + Function [ public function timezone_identifiers_list ] { + } + Function [ public function timezone_abbreviations_list ] { + } + Function [ public function date_default_timezone_set ] { + + - Parameters [1] { + Parameter #0 [ $timezone_identifier ] + } + } + Function [ public function date_default_timezone_get ] { + + - Parameters [0] { + } + } + Function [ public function date_sunrise ] { + + - Parameters [6] { + Parameter #0 [ $time ] + Parameter #1 [ $format ] + Parameter #2 [ $latitude ] + Parameter #3 [ $longitude ] + Parameter #4 [ $zenith ] + Parameter #5 [ $gmt_offset ] + } + } + Function [ public function date_sunset ] { + + - Parameters [6] { + Parameter #0 [ $time ] + Parameter #1 [ $format ] + Parameter #2 [ $latitude ] + Parameter #3 [ $longitude ] + Parameter #4 [ $zenith ] + Parameter #5 [ $gmt_offset ] + } + } + Function [ public function date_sun_info ] { + + - Parameters [3] { + Parameter #0 [ $time ] + Parameter #1 [ $latitude ] + Parameter #2 [ $longitude ] + } + } + } + + - Classes [2] { + Class [ 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 [ public method __construct ] { + } + + Method [ public method format ] { + } + + Method [ public method modify ] { + } + + Method [ public method getTimezone ] { + } + + Method [ public method setTimezone ] { + } + + Method [ public method getOffset ] { + } + + Method [ public method setTime ] { + } + + Method [ public method setDate ] { + } + + Method [ public method setISODate ] { + } + } + } + + Class [ class DateTimeZone ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [2] { + Method [ static public method listAbbreviations ] { + } + + Method [ static public method listIdentifiers ] { + } + } + + - Properties [0] { + } + + - Methods [4] { + Method [ public method __construct ] { + } + + Method [ public method getName ] { + } + + Method [ public method getOffset ] { + } + + Method [ public method getTransitions ] { + } + } + } + } +} + +" +Done diff --git a/sapi/cli/tests/007.phpt b/sapi/cli/tests/007.phpt new file mode 100644 index 0000000000..2725907825 --- /dev/null +++ b/sapi/cli/tests/007.phpt @@ -0,0 +1,52 @@ +--TEST-- +strip comments and whitespace with -w +--SKIPIF-- + +--FILE-- + +'; + +file_put_contents($filename, $code); + +var_dump(`$php -w "$filename"`); +var_dump(`$php -w "wrong"`); +var_dump(`echo "" | $php -w`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(81) " + +" +Could not open input file: wrong +NULL +string(43) " +" +Done diff --git a/sapi/cli/tests/008.phpt b/sapi/cli/tests/008.phpt new file mode 100644 index 0000000000..5bbc26acc2 --- /dev/null +++ b/sapi/cli/tests/008.phpt @@ -0,0 +1,43 @@ +--TEST-- +execute a file with -f +--SKIPIF-- + +--FILE-- + +'; + +file_put_contents($filename, $code); + +var_dump(`$php -f "$filename"`); +var_dump(`$php -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 0000000000..cc910fe1e3 --- /dev/null +++ b/sapi/cli/tests/009.phpt @@ -0,0 +1,23 @@ +--TEST-- +using invalid combinations of cmdline options +--SKIPIF-- + +--FILE-- + +--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 0000000000..60865df712 --- /dev/null +++ b/sapi/cli/tests/010-2.phpt @@ -0,0 +1,35 @@ +--TEST-- +executing a code with -R +--SKIPIF-- + +--FILE-- + +--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 0000000000..5bbcb6ba54 --- /dev/null +++ b/sapi/cli/tests/010.phpt @@ -0,0 +1,47 @@ +--TEST-- +executing a file with -F +--SKIPIF-- + +--FILE-- + +'; + +file_put_contents($filename, $code); + +$txt = ' +test +hello +'; + +file_put_contents($filename_txt, $txt); + +var_dump(`cat "$filename_txt" | "$php" -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 0000000000..ff6595740a --- /dev/null +++ b/sapi/cli/tests/011.phpt @@ -0,0 +1,58 @@ +--TEST-- +syntax check +--SKIPIF-- + +--FILE-- + +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -l "$filename"`); +var_dump(`"$php" -l some.unknown`); + +$code = ' + +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -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: syntax error, unexpected T_PRIVATE, expecting '{' 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 0000000000..ad66fde634 --- /dev/null +++ b/sapi/cli/tests/012.phpt @@ -0,0 +1,38 @@ +--TEST-- +invalid arguments and error messages +--SKIPIF-- + +--FILE-- + +--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 0000000000..6b2b39056d --- /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-- + +--FILE-- + +--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 0000000000..5c4d75a1d6 --- /dev/null +++ b/sapi/cli/tests/014.phpt @@ -0,0 +1,44 @@ +--TEST-- +syntax highlighting +--SKIPIF-- + +--FILE-- + +'; + +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) " +
<?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;
?>
+
+
" +Could not open input file: unknown +NULL +Done diff --git a/sapi/cli/tests/skipif.inc b/sapi/cli/tests/skipif.inc new file mode 100644 index 0000000000..79e6c91004 --- /dev/null +++ b/sapi/cli/tests/skipif.inc @@ -0,0 +1,7 @@ + -- cgit v1.2.1