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 skip a PHPUnit test?
- How to run tests in parallel with PHPUnit?
- How to use hooks in PHPUnit?
- What are PHPUnit required extensions
- How to use the PHPUnit Framework TestCase?
- How to run PHPUnit in quiet mode?
- How to show warnings in PHPUnit?
- How to load fixtures with PHPUnit?
- How to use a listener with PHPUnit?
- How to stop PHPUnit on failure?
See more codes...