samedi 6 août 2016

asserting array equalTo in PHPUnit with some values null

What I have is an array that looks something like this, which gets passed into a method as follows:

$data = array(
    'stuff' => 'things',
    'otherstuff' => NULL,
    'morestuff' => NULL,
);
$object->doStuffWithArray($data);

So I'm writing unit tests, and I need to stub out the doStuffWithArray behavior by asserting the arguments passed into it. So what I'm doing is something like this:

$object_mock->expects($this->once())
            ->with($this->equalTo(array(
                'stuff' => 'things',
                'otherstuff' => NULL,
                'morestuff' => NULL,
            )));

But this is a bit too strict. I'd like for the unit tests to also pass if the fields whose values are NULL aren't in the array at all. Is there any way I can do this in PHPUnit?

Aucun commentaire:

Enregistrer un commentaire