Phpunit: Add array support to methods like assertArrayHasKey and assertObjectHasAttribute

Created on 23 Feb 2016  ·  3Comments  ·  Source: sebastianbergmann/phpunit

$this->assertArrayHasKey(['name', 'email'], $array);
$this->assertObjectHasAttribute(['name', 'email'], $object);

This looks very basic to me.
I don't know why they were not implemented this way.
I taught of opening an issue first, maybe I'm missing something.
If not I'll go ahead and submit a PR.

Most helpful comment

@sebastianbergmann Can you suggest a clean way to test that multiple keys exist in the result? If you are looking for a single key, you can do it in one line. If you are looking for two keys, you need three lines, one to store the result, and two to check the keys.

All 3 comments

I came here just to open this issue! Can this be done please?

I do not think that this makes sense, sorry.

@sebastianbergmann Can you suggest a clean way to test that multiple keys exist in the result? If you are looking for a single key, you can do it in one line. If you are looking for two keys, you need three lines, one to store the result, and two to check the keys.

Was this page helpful?
0 / 5 - 0 ratings