Skip to content

Commit

Permalink
Improve validation in testDomainException
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koriym committed Nov 27, 2024
1 parent 08d52d7 commit 9134552
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/DependencyCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));

Check failure on line 144 in tests/DependencyCompilerTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Function assert() should not be referenced via a fallback global name, but via a use statement.
$fake = new FakeInvalidDependency();
assert($fake instanceof DependencyInterface);

Check failure on line 146 in tests/DependencyCompilerTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Function assert() should not be referenced via a fallback global name, but via a use statement.
(new DependencyCode(new Container()))->getCode($fake);
}

public function testContextualProviderCompile(): void
Expand Down

0 comments on commit 9134552

Please sign in to comment.