Skip to content

Commit

Permalink
Replace TestClass with FakeTestClass in tests
Browse files Browse the repository at this point in the history
This commit introduces a new FakeTestClass and replaces instances of TestClass in unit tests with FakeTestClass. Redundant classes and attributes related to TestClass are removed to streamline the test files and prevent namespace conflicts. These changes will improve maintainability and clarity in the test suite.
  • Loading branch information
koriym committed Nov 30, 2024
1 parent 995bf54 commit ababe09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
13 changes: 3 additions & 10 deletions tests/AirInjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function tearDown(): void

public function testGetInstance(): void
{
$className = TestClass::class;
$className = FakeTestClass::class;
file_put_contents(
$this->scriptDir . '/' . str_replace('\\', '_', $className) . '-' . Name::ANY . '.php',
'<?php return new ' . $className . '();'
Expand All @@ -57,7 +57,7 @@ public function testGetInstance(): void

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

public function testGetInstanceWithName(): void
{
$className = TestClass::class;
$className = FakeTestClass::class;
$name = 'named';
file_put_contents(
$this->scriptDir . '/' . str_replace('\\', '_', $className) . '-' . $name . '.php',
Expand Down Expand Up @@ -145,10 +145,3 @@ public function testWithCompiler(): void
$this->assertInstanceOf(FakeCar::class, $instance);
}
}

class TestClass
{
public function testMethod(string $param): void
{
}
}
12 changes: 12 additions & 0 deletions tests/Fake/FakeTestClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Ray\Compiler;

final class FakeTestClass
{
public function testMethod(string $param): void
{
}
}
21 changes: 3 additions & 18 deletions tests/InjectionPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace Ray\Compiler;

use Attribute;
use PHPUnit\Framework\TestCase;
use Ray\Aop\ReflectionClass;
use Ray\Aop\ReflectionMethod;
use Ray\Di\Di\Qualifier;
use ReflectionParameter;

class InjectionPointTest extends TestCase
Expand All @@ -21,10 +19,10 @@ class InjectionPointTest extends TestCase

protected function setUp(): void
{
$reflectionClass = new \ReflectionClass(FooClass::class);
$reflectionClass = new \ReflectionClass(FakeTestClass::class);
$reflectionMethod = $reflectionClass->getMethod('testMethod');
$this->parameter = $reflectionMethod->getParameters()[0];
$this->injectionPoint = InjectionPoint::getInstance([FooClass::class, 'testMethod', 'param']);
$this->injectionPoint = InjectionPoint::getInstance([FakeTestClass::class, 'testMethod', 'param']);
}

public function testGetParameter(): void
Expand All @@ -45,7 +43,7 @@ public function testGetClass(): void
{
$class = $this->injectionPoint->getClass();
$this->assertInstanceOf(ReflectionClass::class, $class);
$this->assertSame(FooClass::class, $class->getName());
$this->assertSame(FakeTestClass::class, $class->getName());
}

public function testGetQualifiers(): void
Expand All @@ -61,16 +59,3 @@ public function testGetQualifierReturnsNullWhenNoQualifier(): void
$this->assertNull($qualifier);
}
}

class FooClass
{
public function testMethod(string $param): void
{
}
}

#[Attribute]
#[Qualifier]
class TestQualifier
{
}

0 comments on commit ababe09

Please sign in to comment.