Skip to content

Commit 7c01ef9

Browse files
jeroennotenondrejmirtes
authored andcommitted
Add support for assertObjectHasAttribute
1 parent 2968a62 commit 7c01ef9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php

+3
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ private static function getExpressionResolvers(): array
255255
'ArrayHasKey' => function (Scope $scope, Arg $key, Arg $array): FuncCall {
256256
return new \PhpParser\Node\Expr\FuncCall(new Name('array_key_exists'), [$key, $array]);
257257
},
258+
'ObjectHasAttribute' => function (Scope $scope, Arg $property, Arg $object): FuncCall {
259+
return new \PhpParser\Node\Expr\FuncCall(new Name('property_exists'), [$object, $property]);
260+
},
258261
];
259262
}
260263

tests/Type/PHPUnit/data/assert-function.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use function PHPStan\Testing\assertType;
66
use function PHPUnit\Framework\assertArrayHasKey;
7-
use function PHPUnit\Framework\assertArrayNotHasKey;
87
use function PHPUnit\Framework\assertInstanceOf;
8+
use function PHPUnit\Framework\assertObjectHasAttribute;
99

1010
class Foo
1111
{
@@ -30,4 +30,10 @@ public function arrayHasStringKey(array $a): void
3030
assertType("array&hasOffset('key')", $a);
3131
}
3232

33+
public function objectHasAttribute(object $a): void
34+
{
35+
assertObjectHasAttribute('property', $a);
36+
assertType("object&hasProperty(property)", $a);
37+
}
38+
3339
}

0 commit comments

Comments
 (0)