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

Function runTest

frankenphp_test.go:53–109  ·  view source on GitHub ↗
(t *testing.T, test func(func(http.ResponseWriter, *http.Request), *httptest.Server, int), opts *testOptions)

Source from the content-addressed store, hash-verified

51}
52
53func runTest(t *testing.T, test func(func(http.ResponseWriter, *http.Request), *httptest.Server, int), opts *testOptions) {
54 if opts == nil {
55 opts = &testOptions{}
56 }
57 if opts.nbParallelRequests == 0 {
58 opts.nbParallelRequests = 100
59 }
60
61 cwd, _ := os.Getwd()
62 testDataDir := cwd + "/testdata/"
63
64 initOpts := []frankenphp.Option{frankenphp.WithLogger(opts.logger)}
65 if opts.workerScript != "" {
66 workerOpts := []frankenphp.WorkerOption{
67 frankenphp.WithWorkerEnv(opts.env),
68 frankenphp.WithWorkerWatchMode(opts.watch),
69 }
70 initOpts = append(initOpts, frankenphp.WithWorkers("workerName", testDataDir+opts.workerScript, opts.nbWorkers, workerOpts...))
71 }
72 initOpts = append(initOpts, opts.initOpts...)
73 if opts.phpIni != nil {
74 initOpts = append(initOpts, frankenphp.WithPhpIni(opts.phpIni))
75 }
76
77 err := frankenphp.Init(initOpts...)
78 require.NoError(t, err)
79 defer frankenphp.Shutdown()
80
81 opts.requestOpts = append(opts.requestOpts, frankenphp.WithRequestDocumentRoot(testDataDir, false))
82
83 handler := func(w http.ResponseWriter, r *http.Request) {
84 req, err := frankenphp.NewRequestWithContext(r, opts.requestOpts...)
85 assert.NoError(t, err)
86
87 err = frankenphp.ServeHTTP(w, req)
88 if err != nil && !errors.As(err, &frankenphp.ErrRejected{}) {
89 assert.Fail(t, fmt.Sprintf("Received unexpected error:\n%+v", err))
90 }
91 }
92
93 var ts *httptest.Server
94 if opts.realServer {
95 ts = httptest.NewServer(http.HandlerFunc(handler))
96 defer ts.Close()
97 }
98
99 var wg sync.WaitGroup
100 wg.Add(opts.nbParallelRequests)
101 for i := 0; i < opts.nbParallelRequests; i++ {
102 go func(i int) {
103 test(handler, ts, i)
104 wg.Done()
105 }(i)
106 }
107
108 wg.Wait()
109}
110

Callers 15

testHelloWorldFunction · 0.85
TestEnvVarsInPhpIniFunction · 0.85
testFinishRequestFunction · 0.85
testServerVariableFunction · 0.85
testPathInfoFunction · 0.85
testHeadersFunction · 0.85
testResponseHeadersFunction · 0.85
testInputFunction · 0.85
testPostSuperGlobalsFunction · 0.85
testRequestSuperGlobalFunction · 0.85
testCookiesFunction · 0.85

Calls 11

WithLoggerFunction · 0.92
WithWorkerEnvFunction · 0.92
WithWorkerWatchModeFunction · 0.92
WithWorkersFunction · 0.92
WithPhpIniFunction · 0.92
InitFunction · 0.92
ShutdownFunction · 0.92
WithRequestDocumentRootFunction · 0.92
NewRequestWithContextFunction · 0.92
ServeHTTPFunction · 0.92
CloseMethod · 0.80

Tested by

no test coverage detected