Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: how to assert that an array contains a certain value?

I'm writing some unit tests using phpunit and I now want to assert that an array contains a certain value, but the only function I can find is assertArrayHasKey(). There is no assertArrayHasValue whatsoever.

So to be clear I want something like this:

$a = [5, 8, 16];
assertArrayHasValue(8, $a);

All tips are welcome!

like image 254
kramer65 Avatar asked May 22 '14 16:05

kramer65


1 Answers

You can do it with function assertContains()

try this:

$a = [5, 8, 16];
$this->assertContains(8, $a);

ASSERT_CONTAINS

like image 84
Alessandro Minoccheri Avatar answered Oct 18 '22 07:10

Alessandro Minoccheri