From 913455223d8e7945e363b7a2fe7927c3fabb6d7f Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 27 Nov 2024 10:22:55 +0900 Subject: [PATCH] Improve validation in testDomainException Added assertions to check if FakeInvalidDependency class exists and if the instance implemented DependencyInterface. This ensures the test cannot silently fail due to a non-existing class or incorrect type. --- tests/DependencyCompilerTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/DependencyCompilerTest.php b/tests/DependencyCompilerTest.php index 2827904..a528b69 100644 --- a/tests/DependencyCompilerTest.php +++ b/tests/DependencyCompilerTest.php @@ -7,9 +7,11 @@ use DomainException; use PHPUnit\Framework\TestCase; use Ray\Di\Container; +use Ray\Di\DependencyInterface; use Ray\Di\Instance; use Ray\Di\Name; +use function class_exists; use function str_replace; class DependencyCompilerTest extends TestCase @@ -139,7 +141,10 @@ public function testDependencyObjectInstanceCompile(): void public function testDomainException(): void { $this->expectException(DomainException::class); - (new DependencyCode(new Container()))->getCode(new FakeInvalidDependency()); + assert(class_exists(FakeInvalidDependency::class)); + $fake = new FakeInvalidDependency(); + assert($fake instanceof DependencyInterface); + (new DependencyCode(new Container()))->getCode($fake); } public function testContextualProviderCompile(): void