diff --git a/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php b/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php index 600ac33..b4c4f8b 100644 --- a/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php +++ b/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php @@ -410,15 +410,21 @@ private function getExpressionResolvers(): array }, 'isInstanceOf' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr { $classType = $scope->getType($class->value); - $classNameType = $classType->getObjectTypeOrClassStringObjectType(); - $classNames = $classNameType->getObjectClassNames(); - if (count($classNames) !== 1) { + $classNameStrings = $classType->getConstantStrings(); + if (count($classNameStrings) !== 1) { + $classNames = $classType->getObjectClassNames(); + if (count($classNames) === 1) { + return new Instanceof_( + $expr->value, + new Name($classNames[0]) + ); + } return null; } return new Instanceof_( $expr->value, - new Name($classNames[0]) + new Name($classNameStrings[0]->getValue()) ); }, 'isInstanceOfAny' => function (Scope $scope, Arg $expr, Arg $classes): ?Expr { diff --git a/tests/Type/WebMozartAssert/data/impossible-check.php b/tests/Type/WebMozartAssert/data/impossible-check.php index 8175e26..271efc3 100644 --- a/tests/Type/WebMozartAssert/data/impossible-check.php +++ b/tests/Type/WebMozartAssert/data/impossible-check.php @@ -111,6 +111,14 @@ public function implementsInterface($a, string $b, $c): void Assert::implementsInterface($c, self::class); } + /** + * @param class-string<\Exception> $name + */ + public function testInstanceOfClassString(\Exception $e, string $name): void + { + Assert::isInstanceOf($e, $name); + } + } interface Bar {};