xref: /PHP-7.0/sapi/cli/tests/bug43177.phpt (revision 64b167d2)
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
64Connection: close
65X-Powered-By: %s
66Content-type: text/html; charset=UTF-8
67
68OK
69HTTP/1.0 500 Internal Server Error
70Host: localhost
71Connection: close
72X-Powered-By: %s
73Content-type: text/html; charset=UTF-8
74
75HTTP/1.0 500 Internal Server Error
76Host: localhost
77Connection: close
78X-Powered-By: %s
79Content-type: text/html; charset=UTF-8
80
81HTTP/1.0 500 Internal Server Error
82Host: localhost
83Connection: close
84X-Powered-By: %s
85Content-type: text/html; charset=UTF-8
86