test: add tests for exception handling (#11)

This commit is contained in:
Kévin Dunglas
2022-10-11 10:54:30 +02:00
committed by GitHub
parent 46ec897d2e
commit 3712d0d69b
2 changed files with 19 additions and 3 deletions

View File

@@ -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)

View File

@@ -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']}");
};