tests: improve TestFinishRequest (#97)

This commit is contained in:
Kévin Dunglas
2022-11-09 00:53:34 +01:00
committed by GitHub
parent 6ad1f5d277
commit 0a30dd1cb9
2 changed files with 11 additions and 5 deletions

View File

@@ -101,7 +101,9 @@ func testHelloWorld(t *testing.T, opts *testOptions) {
}
func TestFinishRequest_module(t *testing.T) { testFinishRequest(t, nil) }
func TestFinishRequest_worker(t *testing.T) { testFinishRequest(t, &testOptions{workerScript: "index.php"}) }
func TestFinishRequest_worker(t *testing.T) {
testFinishRequest(t, &testOptions{workerScript: "finish-request.php"})
}
func testFinishRequest(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/finish-request.php?i=%d", i), nil)
@@ -110,7 +112,7 @@ func testFinishRequest(t *testing.T, opts *testOptions) {
resp := w.Result()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, fmt.Sprintf("This is output\n"), string(body))
assert.Equal(t, fmt.Sprintf("This is output %d\n", i), string(body))
}, opts)
}

View File

@@ -1,7 +1,11 @@
<?php
echo "This is output\n";
require_once __DIR__.'/_executor.php';
frankenphp_finish_request();
return function () {
echo 'This is output '.($_GET['i'] ?? '')."\n";
echo "This is not";
frankenphp_finish_request();
echo 'This is not';
};