mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
test: add tests for exception handling (#11)
This commit is contained in:
@@ -368,6 +368,24 @@ func testLog(t *testing.T, opts *testOptions) {
|
||||
}, opts)
|
||||
}
|
||||
|
||||
func TestException_module(t *testing.T) { testException(t, &testOptions{}) }
|
||||
func TestException_worker(t *testing.T) {
|
||||
testException(t, &testOptions{workerScript: "exception.php"})
|
||||
}
|
||||
func testException(t *testing.T, opts *testOptions) {
|
||||
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("http://example.com/exception.php?i=%d", i), nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler(w, req)
|
||||
|
||||
resp := w.Result()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
assert.Contains(t, string(body), "hello")
|
||||
assert.Contains(t, string(body), fmt.Sprintf(`Uncaught Exception: request %d`, i))
|
||||
}, opts)
|
||||
}
|
||||
|
||||
func ExampleExecuteScript() {
|
||||
if err := frankenphp.Init(); err != nil {
|
||||
panic(err)
|
||||
|
||||
4
testdata/error.php → testdata/exception.php
vendored
4
testdata/error.php → testdata/exception.php
vendored
@@ -2,9 +2,7 @@
|
||||
|
||||
require_once __DIR__.'/_executor.php';
|
||||
|
||||
throw new Exception('unexpected');
|
||||
|
||||
return function () {
|
||||
echo 'hello';
|
||||
throw new Exception('error');
|
||||
throw new Exception("request {$_GET['i']}");
|
||||
};
|
||||
Reference in New Issue
Block a user