Skip to content

Commit

Permalink
tests: improve TestFinishRequest (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas authored Nov 8, 2022
1 parent 6ad1f5d commit 0a30dd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down
10 changes: 7 additions & 3 deletions testdata/finish-request.php
Original file line number Diff line number Diff line change
@@ -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';
};

0 comments on commit 0a30dd1

Please sign in to comment.