Skip to content

Commit

Permalink
Remove unused code and dependencies in test files
Browse files Browse the repository at this point in the history
Refactored `CompileInjectorExtendedScriptInjectorTest` and `AirInjectorTest` by removing unused properties, setup methods, and redundant tests. Simplifies test logic and ensures a cleaner, more maintainable codebase.
  • Loading branch information
koriym committed Jan 12, 2025
1 parent 5d3352e commit d250a2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
14 changes: 0 additions & 14 deletions tests/AirInjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ public function testGetInstance(): void
$this->assertInstanceOf($className, $instance);
}

public function testGetInstanceSingleton(): void
{
$className = FakeTestClass::class;
$code = '<?php $isSingleton = true; return new ' . $className . '();';
file_put_contents(
$this->scriptDir . '/' . str_replace('\\', '_', $className) . '-' . Name::ANY . '.php',
$code
);

$instance1 = $this->injector->getInstance($className);
$instance2 = $this->injector->getInstance($className);
$this->assertSame($instance1, $instance2);
}

public function testGetInstanceWithName(): void
{
$className = FakeTestClass::class;
Expand Down
26 changes: 12 additions & 14 deletions tests/CompileInjectorExtendedScriptInjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@

class CompileInjectorExtendedScriptInjectorTest extends TestCase
{
/** @var CompileInjector */
private $injector;

protected function setUp(): void
{
@mkdir(__DIR__ . '/tmp');
$this->injector = new CompileInjector(
__DIR__ . '/tmp',
new LazyModule(new FakeCarModule())
);
}

public function testGetInstance(): FakeCar
{
$tmpDir = $this->getTmpDir(__FUNCTION__);
Expand All @@ -53,8 +41,13 @@ public function testDefaultValueInjected(FakeCar $car): void

public function testCompileException(): void
{
$injector = new CompileInjector(
__DIR__ . '/tmp',
new LazyModule(new NullModule())
);

$this->expectException(Unbound::class);
$this->injector->getInstance('invalid-class'); // @phpstan-ignore-line
$injector->getInstance('invalid-class'); // @phpstan-ignore-line
}

public function testToPrototype(): void
Expand Down Expand Up @@ -176,8 +169,13 @@ public function testOnDemandSingleton(): void

public function testOnDemandPrototype(): void
{
$injector = new CompileInjector(
__DIR__ . '/tmp',
new LazyModule(new NullModule())
);

$this->expectException(Unbound::class); // CompileInjector does not support on-demand prototype
$this->injector->getInstance(FakeDependPrototype::class);
$injector->getInstance(FakeDependPrototype::class);
}

public function testOptional(): void
Expand Down

0 comments on commit d250a2a

Please sign in to comment.