phpunitHow to use PHPUnit assertcontains?
PHPUnit assertContains is a method used to check if a given value is contained in an array. It takes two parameters, the first being the expected value and the second being the array to search.
Example code
$array = array('a', 'b', 'c');
$this->assertContains('b', $array);
Output example
OK (1 test, 1 assertion)
Code explanation
$array
: An array containing the values to search.assertContains()
: The method used to check if a given value is contained in an array.'b'
: The expected value to search for.
Helpful links
More of Phpunit
- How to show warnings in PHPUnit?
- How to generate a coverage report with PHPUnit?
- How to check if a JSON contains a value in PHPUnit?
- How to stop PHPUnit on failure?
- How to skip a PHPUnit test?
- How to mock a method with different arguments in PHPUnit?
- What are PHPUnit required extensions
- How to install PHPUnit with a PHAR file?
- How to run tests in parallel with PHPUnit?
- How to order tests with PHPUnit?
See more codes...