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

Function TestRequestSuperGlobalConditional_worker

frankenphp_test.go:350–377  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

348}
349
350func TestRequestSuperGlobalConditional_worker(t *testing.T) {
351 // This test verifies that $_REQUEST works correctly when accessed conditionally
352 // in worker mode. The first request does NOT access $_REQUEST, but subsequent
353 // requests do. This tests the "re-arm" mechanism for JIT auto globals.
354 //
355 // The bug scenario:
356 // - Request 1 (i=1): includes file, $_REQUEST initialized with val=1
357 // - Request 3 (i=3): includes file from cache, $_REQUEST should have val=3
358 // If the bug exists, $_REQUEST would still have val=1 from request 1.
359 phpIni := make(map[string]string)
360 phpIni["auto_globals_jit"] = "1"
361 runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
362 if i%2 == 0 {
363 // Even requests: don't use $_REQUEST
364 body, _ := testGet(fmt.Sprintf("http://example.com/request-superglobal-conditional.php?val=%d", i), handler, t)
365 assert.Contains(t, body, "SKIPPED")
366 assert.Contains(t, body, fmt.Sprintf("'val' => '%d'", i))
367 } else {
368 // Odd requests: use $_REQUEST
369 body, _ := testGet(fmt.Sprintf("http://example.com/request-superglobal-conditional.php?use_request=1&val=%d", i), handler, t)
370 assert.Contains(t, body, "REQUEST:")
371 assert.Contains(t, body, "REQUEST_COUNT:2", "$_REQUEST should have ONLY current request's data (2 keys: use_request and val)")
372 assert.Contains(t, body, fmt.Sprintf("'val' => '%d'", i), "request data is not present")
373 assert.Contains(t, body, "'use_request' => '1'")
374 assert.Contains(t, body, "VAL_CHECK:MATCH", "BUG: $_REQUEST contains stale data from previous request! Body: "+body)
375 }
376 }, &testOptions{workerScript: "request-superglobal-conditional.php", phpIni: phpIni})
377}
378
379func TestCookies_module(t *testing.T) { testCookies(t, nil) }
380func TestCookies_worker(t *testing.T) { testCookies(t, &testOptions{workerScript: "cookies.php"}) }

Callers

nothing calls this directly

Calls 2

runTestFunction · 0.85
testGetFunction · 0.85

Tested by

no test coverage detected