Skip to content

Commit

Permalink
Fix handling assertInstanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 21, 2023
1 parent 4b17a23 commit 7e43c8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Expand Up @@ -124,15 +124,15 @@ private static function getExpressionResolvers(): array
if (self::$resolvers === null) {
self::$resolvers = [
'InstanceOf' => static function (Scope $scope, Arg $class, Arg $object): ?Instanceof_ {
$classType = $scope->getType($class->value)->getClassStringObjectType();
$classNames = $classType->getObjectClassNames();
$classType = $scope->getType($class->value);
$classNames = $classType->getConstantStrings();
if (count($classNames) !== 1) {
return null;
}

return new Instanceof_(
$object->value,
new Name($classNames[0])
new Name($classNames[0]->getValue())
);
},
'Same' => static function (Scope $scope, Arg $expected, Arg $actual): Identical {
Expand Down
9 changes: 9 additions & 0 deletions tests/Rules/PHPUnit/data/impossible-assert-method-call.php
Expand Up @@ -20,4 +20,13 @@ public function doBar(object $o): void
$this->assertEmpty($o);
}

/**
* @param class-string<\Exception> $name
* @return void
*/
public function doBaz(\Exception $e, string $name): void
{
$this->assertInstanceOf($name, $e);
}

}

0 comments on commit 7e43c8f

Please sign in to comment.