MCPcopy Index your code
hub / github.com/php/frankenphp / TestWorker

Function TestWorker

worker_test.go:21–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestWorker(t *testing.T) {
22 runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
23 formData := url.Values{"baz": {"bat"}}
24 req := httptest.NewRequest("POST", "http://example.com/worker.php?foo=bar", strings.NewReader(formData.Encode()))
25 req.Header.Set("Content-Type", strings.Clone("application/x-www-form-urlencoded"))
26 w := httptest.NewRecorder()
27 handler(w, req)
28
29 resp := w.Result()
30 body, _ := io.ReadAll(resp.Body)
31
32 assert.Contains(t, string(body), fmt.Sprintf("Requests handled: %d", i*2))
33
34 formData2 := url.Values{"baz2": {"bat2"}}
35 req2 := httptest.NewRequest("POST", "http://example.com/worker.php?foo2=bar2", strings.NewReader(formData2.Encode()))
36 req2.Header.Set("Content-Type", strings.Clone("application/x-www-form-urlencoded"))
37
38 w2 := httptest.NewRecorder()
39 handler(w2, req2)
40
41 resp2 := w2.Result()
42 body2, _ := io.ReadAll(resp2.Body)
43
44 assert.Contains(t, string(body2), fmt.Sprintf("Requests handled: %d", i*2+1))
45 }, &testOptions{workerScript: "worker.php", nbWorkers: 1, nbParallelRequests: 1})
46}
47
48func TestWorkerDie(t *testing.T) {
49 runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {

Callers

nothing calls this directly

Calls 3

runTestFunction · 0.85
SetMethod · 0.80
ResultMethod · 0.80

Tested by

no test coverage detected