phpunitHow to use PHPUnit assert to check an array?
PHPUnit assert is a powerful tool for testing the correctness of your code. It can be used to check an array by using the assertEquals()
method.
$expected = array('a', 'b', 'c');
$actual = array('a', 'b', 'c');
$this->assertEquals($expected, $actual);
The above code will check if the two arrays are equal. If they are, the test will pass.
Code explanation
$expected
: The expected array.$actual
: The actual array.assertEquals()
: The method used to compare the two arrays.
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...