From 61ece0130ab3f743ce1d6edfe993aa7bf76dd802 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Thu, 9 May 2024 10:40:34 +0900 Subject: [PATCH] Add FakeApp class and serialization test The new class FakeApp has been implemented for testing purposes. In addition, new test cases have been added to CompileInjectorTest to verify the correct serialization and deserialization of the new FakeApp class. The serialization test requires PHP version 7.4 or higher. --- tests/CompileInjectorTest.php | 13 +++++++++++++ tests/Fake/FakeApp.php | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/Fake/FakeApp.php diff --git a/tests/CompileInjectorTest.php b/tests/CompileInjectorTest.php index 813bf68..9681251 100644 --- a/tests/CompileInjectorTest.php +++ b/tests/CompileInjectorTest.php @@ -106,4 +106,17 @@ public function testCompileFaillureLog(): void $log = (string) file_get_contents($logFile); $this->assertStringContainsString('Error', $log); } + + /** @requires PHP >= 7.4 */ + public function testSeirialzeInAarray() + { + $app = new FakeApp(new CompileInjector(__DIR__ . '/tmp', new FakeLazyModule())); + $serializedApp = serialize($app); + $unserializedApp = unserialize($serializedApp); + + assert($unserializedApp instanceof FakeApp); + + $instance = $unserializedApp->i->getInstance(FakeCarInterface::class); + $this->assertInstanceOf(FakeCar::class, $instance); + } } diff --git a/tests/Fake/FakeApp.php b/tests/Fake/FakeApp.php new file mode 100644 index 0000000..edc1678 --- /dev/null +++ b/tests/Fake/FakeApp.php @@ -0,0 +1,27 @@ +injector = $injector; + } + + public function __serialize(): array + { + return ['injector' => $this->injector]; + } + + public function __unserialize(array $data) + { + $this->injector = $data['injector']; + } +}