How to test inner arrays with phpunit
I have to test an array with inner arrays.
my array looks like the following.
$testdata=Array
(
[0] => Array
(
[label] => 'Ammy'
[idr] => 'user7'
[rel] => 7
)
[1] => Array
(
[label] => 'sidh'
[idr] => user8
[rel] => 8
)
[2] => Array
(
[label] => 'Alan'
[idr] => 'user9'
[rel] => 9
)
)
in this case my requirement is to assert whether the keys for inner array present using assertArrayHasKey() assertion of phpunit. I tried to do it like this
foreach ($testdata as $values) {
//print_r($values);
$this->assertArrayHasKey('idr', $values);
$this->assertArrayHasKey('rel', $values);
}
but this is not working for me. even the control does not go inside the foreach() loop.
please suggest me some solution for this.
foreach ($testdata as $values) {
//print_r($values);
$this->assertArrayHasKey('idr', $values);
$this->assertArrayHasKey('rel', $values);
}
this part in my question works fine. actually i was not getting the array itself in the test scenario. so it was not going inside the foreach(). now it is solved. i had a mistake in passing args to the function.