xref: /PHP-7.3/sapi/cli/tests/bug43177.phpt (revision 782352c5)
1--TEST--
2Bug #61977 Test exit code for various errors
3--SKIPIF--
4<?php
5include "skipif.inc";
6?>
7--FILE--
8<?php
9include "php_cli_server.inc";
10php_cli_server_start(<<<'SCRIPT'
11	ini_set('display_errors', 0);
12	switch($_SERVER["REQUEST_URI"]) {
13	        case "/parse":
14	                try {
15                        eval("this is a parse error");
16                    } catch (ParseError $e) {
17                    }
18					echo "OK\n";
19	                break;
20	        case "/fatal":
21	                eval("foo();");
22					echo "OK\n";
23	                break;
24			case "/compile":
25					eval("class foo { final private final function bar() {} }");
26					echo "OK\n";
27					break;
28			case "/fatal2":
29					foo();
30					echo "OK\n";
31					break;
32	        default:
33	                return false;
34	}
35SCRIPT
36);
37
38list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
39$port = intval($port)?:80;
40
41foreach(array("parse", "fatal", "fatal2", "compile") as $url) {
42	$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
43	if (!$fp) {
44  		die("connect failed");
45	}
46
47	if(fwrite($fp, <<<HEADER
48GET /$url HTTP/1.1
49Host: {$host}
50
51
52HEADER
53)) {
54        while (!feof($fp)) {
55                echo fgets($fp);
56        }
57	}
58}
59
60?>
61--EXPECTF--
62HTTP/1.1 200 OK
63Host: localhost
64Date: %s
65Connection: close
66X-Powered-By: %s
67Content-type: text/html; charset=UTF-8
68
69OK
70HTTP/1.0 500 Internal Server Error
71Host: localhost
72Date: %s
73Connection: close
74X-Powered-By: %s
75Content-type: text/html; charset=UTF-8
76
77HTTP/1.0 500 Internal Server Error
78Host: localhost
79Date: %s
80Connection: close
81X-Powered-By: %s
82Content-type: text/html; charset=UTF-8
83
84HTTP/1.0 500 Internal Server Error
85Host: localhost
86Date: %s
87Connection: close
88X-Powered-By: %s
89Content-type: text/html; charset=UTF-8
90