xref: /PHP-8.3/sapi/cli/tests/bug78323.phpt (revision dcc3255b)
1--TEST--
2Bug #78323 Test exit code and error message for invalid parameters
3--SKIPIF--
4<?php
5include "skipif.inc";
6?>
7--FILE--
8<?php
9$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
10
11// There are 3 types of option errors:
12// 1 : in flags
13// 2 option not found
14// 3 no argument for option
15
16
17// colon in flags
18ob_start();
19passthru("$php -a:Z 2>&1", $exitCode);
20$output = ob_get_contents();
21ob_end_clean();
22
23$lines = preg_split('/\R/', $output);
24echo $lines[0], "\n",
25     $lines[1], "\n",
26     "Done: $exitCode\n\n";
27
28
29// option not found
30ob_start();
31passthru("$php -Z 2>&1", $exitCode);
32$output = ob_get_contents();
33ob_end_clean();
34
35$lines = preg_split('/\R/', $output);
36echo $lines[0], "\n",
37     $lines[1], "\n",
38     "Done: $exitCode\n\n";
39
40
41// no argument for option
42ob_start();
43passthru("$php --memory-limit=1G 2>&1", $exitCode);
44$output = ob_get_contents();
45ob_end_clean();
46
47$lines = preg_split('/\R/', $output);
48echo $lines[0], "\n",
49     $lines[1], "\n",
50     "Done: $exitCode\n\n";
51
52
53// Successful execution
54ob_start();
55passthru("$php -dmemory-limit=1G -v", $exitCode);
56$output = ob_get_contents();
57ob_end_clean();
58
59$lines = preg_split('/\R/', $output);
60echo $lines[0], "\n",
61     "Done: $exitCode\n";
62
63?>
64--EXPECTF--
65Error in argument %d, char %d: : in flags
66Usage: %s [options] [-f] <file> [--] [args...]
67Done: 1
68
69Error in argument %d, char %d: option not found %s
70Usage: %s [options] [-f] <file> [--] [args...]
71Done: 1
72
73Error in argument %d, char %d: no argument for option %s
74Usage: %s [options] [-f] <file> [--] [args...]
75Done: 1
76
77PHP %s
78Done: 0
79