From ac336a80adc73f5c09ae039ea8e5f4f293c8b806 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Fri, 7 Aug 2020 12:45:21 +0200 Subject: [PATCH 1/2] Improve PHPUnit assertions The two assertion methods: - assertArrayHasKey - assertArrayNotHasKey benefit from a @psalm-assert as well. --- stubs/Assert_75.phpstub | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/stubs/Assert_75.phpstub b/stubs/Assert_75.phpstub index 37e6ff2..124d105 100644 --- a/stubs/Assert_75.phpstub +++ b/stubs/Assert_75.phpstub @@ -3,6 +3,26 @@ namespace PHPUnit\Framework; abstract class Assert { + /** + * Asserts that an array has a specified key. + * + * @param int|string $key + * @param mixed $array + * @psalm-assert array $array + * @return void + */ + public static function assertArrayHasKey($key, $array, string $message = '') {} + + /** + * Asserts that an array does not have a specified key. + * + * @param int|string $key + * @param mixed $array + * @psalm-assert array $array + * @return void + */ + public static function assertArrayNotHasKey($key, $array, string $message = '') {} + /** * @param mixed $actual * @psalm-assert array $actual From 1e3e3a1ace239def8c4b722db6e4b6b94721cf6b Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Fri, 7 Aug 2020 14:30:34 +0200 Subject: [PATCH 2/2] squash! Improve PHPUnit assertions Make PHPUnit assertion of an array-key of an actual array redundant condition free on evaluation and reconciliation of an actual array to the array type in the psalm-assertion. --- stubs/Assert_75.phpstub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/Assert_75.phpstub b/stubs/Assert_75.phpstub index 124d105..c3a8e8b 100644 --- a/stubs/Assert_75.phpstub +++ b/stubs/Assert_75.phpstub @@ -8,7 +8,7 @@ abstract class Assert * * @param int|string $key * @param mixed $array - * @psalm-assert array $array + * @psalm-assert array{} $array * @return void */ public static function assertArrayHasKey($key, $array, string $message = '') {}