Evet öyle. PHPUnit API Assert.
Özellikle:
void assertEquals(array $expected, array $actual)
Reports an error if the two arrays $expected and $actual are not equal.
void assertEquals(array $expected, array $actual, string $message)
Reports an error identified by $message if the two arrays $expected and $actual are not equal.
void assertNotEquals(array $expected, array $actual)
Reports an error if the two arrays $expected and $actual are equal.
void assertNotEquals(array $expected, array $actual, string $message)
Reports an error identified by $message if the two arrays $expected and $actual are equal.
Testi Kodu:
public function testArraysEqual() {
$arr1 = array( 'hello' => 'a', 'goodbye' => 'b');
$arr2 = array( 'hello' => 'a', 'goodbye' => 'b');
$this->assertEquals($arr1, $arr2);
}
public function testArraysNotEqual() {
$arr1 = array( 'hello' => 'a', 'goodbye' => 'b');
$arr2 = array( 'hello' => 'b', 'goodbye' => 'a');
$this->assertNotEquals($arr1, $arr2);
}
[EDIT]
Burada sipariş aLists dışında için kodu:
public function testArraysEqualReverse() {
$arr1 = array( 'hello' => 'a', 'goodbye' => 'b');
$arr2 = array( 'goodbye' => 'b', 'hello' => 'a');
$this->assertEquals($arr1, $arr2);
}
Bu test başarısız olur:
public function testArraysOutOfOrderEqual() {
$arr1 = array( 'a', 'b');
$arr2 = array( 'b', 'a');
$this->assertEquals($arr1, $arr2);
}
Mesajı ile:
Failed asserting that
Array
(
[0] => b
[1] => a
)
is equal to
Array
(
[0] => a
[1] => b
)