Skip to content

Commit

Permalink
Add FakeApp class and serialization test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koriym committed May 9, 2024
1 parent 23610e9 commit 61ece01
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/CompileInjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Check failure on line 111 in tests/CompileInjectorTest.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Method Ray\Compiler\CompileInjectorTest::testSeirialzeInAarray() has no return type specified.
{
$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);

Check failure on line 119 in tests/CompileInjectorTest.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Access to an undefined property Ray\Compiler\FakeApp::$i.
$this->assertInstanceOf(FakeCar::class, $instance);
}
}
27 changes: 27 additions & 0 deletions tests/Fake/FakeApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Ray\Compiler;

use Ray\Di\InjectorInterface;

final class FakeApp
{
public $injector;

public function __construct(InjectorInterface $injector)
{
$this->injector = $injector;
}

public function __serialize(): array
{
return ['injector' => $this->injector];
}

public function __unserialize(array $data)
{
$this->injector = $data['injector'];
}
}

0 comments on commit 61ece01

Please sign in to comment.