Skip to content

Commit 614acc1

Browse files
authored
Add support for assertObjectHasProperty
1 parent 6536e66 commit 614acc1

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ private static function getExpressionResolvers(): array
276276
'ObjectHasAttribute' => staticfunction (Scope$scope, Arg$property, Arg$object): FuncCall {
277277
returnnewFuncCall(newName('property_exists'), [$object, $property]);
278278
},
279+
'ObjectHasProperty' => staticfunction (Scope$scope, Arg$property, Arg$object): FuncCall {
280+
returnnewFuncCall(newName('property_exists'), [$object, $property]);
281+
},
279282
'Contains' => staticfunction (Scope$scope, Arg$needle, Arg$haystack): Expr {
280283
returnnewExpr\BinaryOp\BooleanOr(
281284
newExpr\Instanceof_($haystack->value, newName('Traversable')),

‎tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ class AssertFunctionTypeSpecifyingExtensionTest extends TypeInferenceTestCase
1111
/** @return mixed[] */
1212
publicfunctiondataFileAsserts(): iterable
1313
{
14-
if (!function_exists('PHPUnit\\Framework\\assertInstanceOf')) {
15-
return [];
14+
if (function_exists('PHPUnit\\Framework\\assertInstanceOf')) {
15+
yieldfrom$this->gatherAssertTypes(__DIR__ . '/data/assert-function.php');
1616
}
1717

18-
yieldfrom$this->gatherAssertTypes(__DIR__ . '/data/assert-function.php');
18+
if (function_exists('PHPUnit\\Framework\\assertObjectHasProperty')) {
19+
yieldfrom$this->gatherAssertTypes(__DIR__ . '/data/assert-function-9.6.11.php');
20+
}
21+
22+
return [];
1923
}
2024

2125
/**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespaceAssertFunction;
4+
5+
usefunctionPHPStan\Testing\assertType;
6+
usefunctionPHPUnit\Framework\assertObjectHasProperty;
7+
8+
class Foo
9+
{
10+
11+
publicfunctionobjectHasProperty(object$a): void
12+
{
13+
assertObjectHasProperty('property', $a);
14+
assertType("object&hasProperty(property)", $a);
15+
}
16+
17+
}

0 commit comments

Comments
 (0)