Skip to content

Commit 3d1985f

Browse files
committed
Use assertions
1 parent 875a963 commit 3d1985f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/StaticMethodMock.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class StaticMethodMock
1313
private static $autoloader = null;
1414
/** @var array<string,StaticMethodMock> */
1515
public static array $mocks = [];
16+
1617
/** @var string */
1718
private string $className;
1819
/** @var TestCase */
@@ -25,14 +26,14 @@ public function __construct(string $className, TestCase $testCase)
2526
{
2627
$this->className = $className;
2728
$this->testCase = $testCase;
28-
self::$mocks[$className] = $this;
29+
self::$mocks[$this->className] = $this;
2930
if (self::$autoloader === null) {
30-
self::$autoloader = function (string $class): void {
31-
if ($class === $this->className) {
32-
$namespace = substr($this->className, 0, strrpos($this->className, '\\') + 0);
33-
$shortClassName = substr($this->className, strrpos($this->className, '\\') + 1);
34-
eval('namespace ' . $namespace . ' { class ' . $shortClassName . ' { public static function __callStatic($name, $arguments) { return \MintyPHP\Mocking\StaticMethodMock::handleStaticCall(\'' . $this->className . '\', $name, $arguments); } } }');
35-
}
31+
self::$autoloader = static function (string $class): void {
32+
if (in_array($class, array_keys(self::$mocks))) {
33+
$namespace = substr($class, 0, strrpos($class, '\\') + 0);
34+
$shortClassName = substr($class, strrpos($class, '\\') + 1);
35+
eval("namespace $namespace { class $shortClassName { public static function __callStatic(\$name, \$arguments) { return \\MintyPHP\\Mocking\\StaticMethodMock::handleStaticCall('$class', \$name, \$arguments); } } }");
36+
}
3637
};
3738
spl_autoload_register(self::$autoloader, true, true);
3839
}

0 commit comments

Comments
 (0)