Expecting partial arrays using PHPUnit mock objects

Viewed 6346

What is the best way to test for multiple array keys in a PHPUnit mock with() clause?

For example, to test whether a method calls 2nd argument is an array containing a 'foo' key:

$this->stubDispatcher->expects($this->once())
        ->method('send')
        ->with('className', $this->arrayHasKey('foo'));

What I'd like to do is something like $this->arrayHasKey('foo', 'bar') while not actually matching the exact contents of the array.

2 Answers
Related