Improve PHPUnit assertions
Improve PHPUnit assertions
The two assertion methods:
- assertArrayHasKey
- assertArrayNotHasKey
benefit from a @psalm-assert as well.
Kind of interesting with this change in a test-case:
public function testEnvServerSuperglobalFiltering()
{
$server = $_SERVER;
$server['foo=bar'] = 'baz';
self::assertArrayHasKey('HOME', $server, 'pre-condition');
^
`--- 133:15
psalm says:
ERROR: RedundantCondition - tests/unit/LibTest.php:133:15 - Found a redundant condition when evaluating $server and trying to reconcile type 'array{foo=bar: string(baz)}<array-key, mixed>' to array (see https://psalm.dev/122)
self::assertArrayHasKey('HOME', $server, 'pre-condition');
looks like that now being an assertion psalm over-emphasizes the fact that it's a known type now, feeling a bit like not seeing the whole picture, this came a bit unexpected to me.
Just pushed another change that turns @psalm-assert array $array to @psalm-assert array{} $array which makes the evaluation redundant condition free.
\Enhance\Assert::areIdentical($expected, $actual);
\Enhance\Assert::throws($someClass, 'MethodName'); You can also pass arguments to be used in the target method call:
\Enhance\Assert::throws($someClass, 'MethodName', array(2, 'Arg2', 5));
@Rahul-coder01 Care to elaborate? I must admit I have no clue what that code is referring to but might just be me not seeing the wood for the trees. Thanks.