Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6aaff11

Browse files
simonhammesondrejmirtes
authored andcommitted
Add support for assertArrayHasKey (#100)
1 parent efc0099 commit 6aaff11

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ private static function getExpressionResolvers(): array
252252
]
253253
);
254254
},
255+
'ArrayHasKey' => function (Scope $scope, Arg $key, Arg $array): FuncCall {
256+
return new \PhpParser\Node\Expr\FuncCall(new Name('array_key_exists'), [$key, $array]);
257+
},
255258
];
256259
}
257260

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace AssertFunction;
44

55
use function PHPStan\Testing\assertType;
6+
use function PHPUnit\Framework\assertArrayHasKey;
7+
use function PHPUnit\Framework\assertArrayNotHasKey;
68
use function PHPUnit\Framework\assertInstanceOf;
79

810
class Foo
@@ -17,4 +19,15 @@ public function doFoo($o): void
1719
assertType(self::class, $o);
1820
}
1921

22+
public function arrayHasNumericKey(array $a): void {
23+
assertArrayHasKey(0, $a);
24+
assertType('array&hasOffset(0)', $a);
25+
}
26+
27+
public function arrayHasStringKey(array $a): void
28+
{
29+
assertArrayHasKey('key', $a);
30+
assertType("array&hasOffset('key')", $a);
31+
}
32+
2033
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /