9951 explained code solutions for 126 technologies


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

Edit this code on GitHub