mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
tests: improve TestFinishRequest (#97)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
10
testdata/finish-request.php
vendored
10
testdata/finish-request.php
vendored
@@ -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';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user