Question

In PHPUnit I am trying to test that two arrays are equal: one from the function I am testing and one from a Flat XML dataset. However, the array that the function generates has an additional array nested inside it, and I don't know how to include an array in the XML Dataset to mirror it. Is it possible to do so, or will I have to find a workaround?

This is what the output of my PHPUnit test looks like:

Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => Array (
         'FLCT_alt' => 'asfda'
-        'composers' => Array ()

@@ @@
         'FLCT_alt' => 'ksksksks'
-        'composers' => Array ()

etc.

Was it helpful?

Solution

If you need some simple testing, you can check ids in the first array, element counts etc... to avoid the need for the sub array to be tested.

$this->assertEquals(5, count($ArrayVariable));

$this->assertArrayHasKey('FLCT_alt, $ArrayVariable);
$this->assertEquals('ksksksks', $ArrayVariable['FLCT_alt']));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top