Skip to content

Commit

Permalink
Add support for assertObjectHasProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirone authored Aug 25, 2023
1 parent 6536e66 commit 614acc1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ private static function getExpressionResolvers(): array
'ObjectHasAttribute' => static function (Scope $scope, Arg $property, Arg $object): FuncCall {
return new FuncCall(new Name('property_exists'), [$object, $property]);
},
'ObjectHasProperty' => static function (Scope $scope, Arg $property, Arg $object): FuncCall {
return new FuncCall(new Name('property_exists'), [$object, $property]);
},
'Contains' => static function (Scope $scope, Arg $needle, Arg $haystack): Expr {
return new Expr\BinaryOp\BooleanOr(
new Expr\Instanceof_($haystack->value, new Name('Traversable')),
Expand Down
10 changes: 7 additions & 3 deletions tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ class AssertFunctionTypeSpecifyingExtensionTest extends TypeInferenceTestCase
/** @return mixed[] */
public function dataFileAsserts(): iterable
{
if (!function_exists('PHPUnit\\Framework\\assertInstanceOf')) {
return [];
if (function_exists('PHPUnit\\Framework\\assertInstanceOf')) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/assert-function.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/assert-function.php');
if (function_exists('PHPUnit\\Framework\\assertObjectHasProperty')) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/assert-function-9.6.11.php');
}

return [];
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/Type/PHPUnit/data/assert-function-9.6.11.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace AssertFunction;

use function PHPStan\Testing\assertType;
use function PHPUnit\Framework\assertObjectHasProperty;

class Foo
{

public function objectHasProperty(object $a): void
{
assertObjectHasProperty('property', $a);
assertType("object&hasProperty(property)", $a);
}

}

0 comments on commit 614acc1

Please sign in to comment.