mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
chore: add tests regarding persistent objects
This commit is contained in:
@@ -294,6 +294,26 @@ func testPhpInfo(t *testing.T, opts *testOptions) {
|
||||
}, opts)
|
||||
}
|
||||
|
||||
func TestPersistentObject_module(t *testing.T) { testPersistentObject(t, nil) }
|
||||
func TestPersistentObject_worker(t *testing.T) {
|
||||
testPersistentObject(t, &testOptions{workerScript: "persistent-object.php"})
|
||||
}
|
||||
func testPersistentObject(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/persistent-object.php?i=%d", i), nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler(w, req)
|
||||
|
||||
resp := w.Result()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
assert.Equal(t, string(body), fmt.Sprintf(`request: %d
|
||||
class exists: 1
|
||||
id: obj1
|
||||
object id: 1`, i))
|
||||
}, opts)
|
||||
}
|
||||
|
||||
func ExampleExecuteScript() {
|
||||
if err := frankenphp.Init(); err != nil {
|
||||
panic(err)
|
||||
|
||||
2
testdata/_executor.php
vendored
2
testdata/_executor.php
vendored
@@ -7,3 +7,5 @@ if (!isset($_SERVER['FRANKENPHP_WORKER'])) {
|
||||
}
|
||||
|
||||
while (frankenphp_handle_request($fn)) {}
|
||||
|
||||
return;
|
||||
|
||||
6
testdata/persistent-object-require.php
vendored
Normal file
6
testdata/persistent-object-require.php
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
class MyObject
|
||||
{
|
||||
public function __construct(public string $id) {}
|
||||
}
|
||||
13
testdata/persistent-object.php
vendored
Normal file
13
testdata/persistent-object.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/_executor.php';
|
||||
require_once __DIR__.'/persistent-object-require.php';
|
||||
|
||||
$foo = new MyObject('obj1');
|
||||
|
||||
return function () use ($foo) {
|
||||
echo 'request: ' . $_GET['i'] . "\n";
|
||||
echo 'class exists: ' . class_exists(MyObject::class) . "\n";
|
||||
echo 'id: ' . $foo->id . "\n";
|
||||
echo 'object id: '. spl_object_id($foo);
|
||||
};
|
||||
Reference in New Issue
Block a user