Skip to content

Commit

Permalink
Update tests with script path and class changes
Browse files Browse the repository at this point in the history
Modified `CompileInjectorTest` to include a fake module during compile and ensure the bindings log file exists before getting instances. Updated `VisitorCompilerTest` to use script paths for instantiation, ensuring consistency with new script-based instantiation logic. These changes enhance test reliability and alignment with recent codebase updates.
  • Loading branch information
koriym committed Nov 30, 2024
1 parent d865fd1 commit f05a597
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions tests/CompileInjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function setUp(): void

public function testCompile(): void
{
$this->injector->compile();
$this->injector->compile(new FakeLazyModule()());
// built in script
$this->assertFileExists(__DIR__ . '/tmp/-Ray_Compiler_Annotation_Compile.php');
$this->assertFileExists(__DIR__ . '/tmp/-Ray_Di_Annotation_ScriptDir.php');
Expand Down Expand Up @@ -83,6 +83,7 @@ public function testUnbound(): void
public function testUnboundCompileLogFile(): void
{
$this->expectException(Unbound::class);
$this->injector->getInstance(FakeCar2::class);
$this->assertFileExists(__DIR__ . '/tmp/_bindings.log');
$this->injector->getInstance(FakeCar3::class);
}
}
14 changes: 7 additions & 7 deletions tests/VisitorCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public function testDependencyCompile(): Container
assert($dependency instanceof AcceptInterface);
$code = $dependency->accept(new CompileVisitor($container));
$expected = <<<'EOT'
$instance = new \Ray\Compiler\FakeCar($prototype('Ray\Compiler\FakeEngineInterface-', ['Ray\Compiler\FakeCar', '__construct', 'engine']));
$instance->setTires($prototype('Ray\Compiler\FakeTyreInterface-', ['Ray\Compiler\FakeCar', 'setTires', 'frontTyre']), $prototype('Ray\Compiler\FakeTyreInterface-', ['Ray\Compiler\FakeCar', 'setTires', 'rearTyre']), NULL);
$instance->setHardtop($prototype('Ray\Compiler\FakeHardtopInterface-', ['Ray\Compiler\FakeCar', 'setHardtop', 'hardtop']));
$instance->setMirrors($singleton('Ray\Compiler\FakeMirrorInterface-right', ['Ray\Compiler\FakeCar', 'setMirrors', 'rightMirror']), $singleton('Ray\Compiler\FakeMirrorInterface-left', ['Ray\Compiler\FakeCar', 'setMirrors', 'leftMirror']));
$instance->setSpareMirror($singleton('Ray\Compiler\FakeMirrorInterface-right', ['Ray\Compiler\FakeCar', 'setSpareMirror', 'rightMirror']));
$instance->setHandle($prototype('Ray\Compiler\FakeHandleInterface-', ['Ray\Compiler\FakeCar', 'setHandle', 'handle']));
$instance->setOil($prototype('Ray\Compiler\FakeOilInterface-', ['Ray\Compiler\FakeCar', 'setOil', 'oil']));
$instance = new \Ray\Compiler\FakeCar(\Ray\Compiler\prototype($scriptDir, '/Ray_Compiler_FakeEngineInterface-.php', ['Ray\Compiler\FakeCar', '__construct', 'engine']));
$instance->setTires(\Ray\Compiler\prototype($scriptDir, '/Ray_Compiler_FakeTyreInterface-.php', ['Ray\Compiler\FakeCar', 'setTires', 'frontTyre']), \Ray\Compiler\prototype($scriptDir, '/Ray_Compiler_FakeTyreInterface-.php', ['Ray\Compiler\FakeCar', 'setTires', 'rearTyre']), NULL);
$instance->setHardtop(\Ray\Compiler\prototype($scriptDir, '/Ray_Compiler_FakeHardtopInterface-.php', ['Ray\Compiler\FakeCar', 'setHardtop', 'hardtop']));
$instance->setMirrors(\Ray\Compiler\singleton($scriptDir, $singletons, 'Ray\Compiler\FakeMirrorInterface-right', '/Ray_Compiler_FakeMirrorInterface-right.php', ['Ray\Compiler\FakeCar', 'setMirrors', 'rightMirror']), \Ray\Compiler\singleton($scriptDir, $singletons, 'Ray\Compiler\FakeMirrorInterface-left', '/Ray_Compiler_FakeMirrorInterface-left.php', ['Ray\Compiler\FakeCar', 'setMirrors', 'leftMirror']));
$instance->setSpareMirror(\Ray\Compiler\singleton($scriptDir, $singletons, 'Ray\Compiler\FakeMirrorInterface-right', '/Ray_Compiler_FakeMirrorInterface-right.php', ['Ray\Compiler\FakeCar', 'setSpareMirror', 'rightMirror']));
$instance->setHandle(\Ray\Compiler\prototype($scriptDir, '/Ray_Compiler_FakeHandleInterface-.php', ['Ray\Compiler\FakeCar', 'setHandle', 'handle']));
$instance->setOil(\Ray\Compiler\prototype($scriptDir, '/Ray_Compiler_FakeOilInterface-.php', ['Ray\Compiler\FakeCar', 'setOil', 'oil']));
$instance->postConstruct();
$isSingleton = false;
return $instance;
Expand Down

0 comments on commit f05a597

Please sign in to comment.