Skip to content

Commit

Permalink
Add support for assertArrayHasKey (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhammes authored and ondrejmirtes committed Jul 14, 2021
1 parent efc0099 commit 6aaff11
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ private static function getExpressionResolvers(): array
]
);
},
'ArrayHasKey' => function (Scope $scope, Arg $key, Arg $array): FuncCall {
return new \PhpParser\Node\Expr\FuncCall(new Name('array_key_exists'), [$key, $array]);
},
];
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Type/PHPUnit/data/assert-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace AssertFunction;

use function PHPStan\Testing\assertType;
use function PHPUnit\Framework\assertArrayHasKey;
use function PHPUnit\Framework\assertArrayNotHasKey;
use function PHPUnit\Framework\assertInstanceOf;

class Foo
Expand All @@ -17,4 +19,15 @@ public function doFoo($o): void
assertType(self::class, $o);
}

public function arrayHasNumericKey(array $a): void {
assertArrayHasKey(0, $a);
assertType('array&hasOffset(0)', $a);
}

public function arrayHasStringKey(array $a): void
{
assertArrayHasKey('key', $a);
assertType("array&hasOffset('key')", $a);
}

}

0 comments on commit 6aaff11

Please sign in to comment.