ownking
ownking

Reputation: 2006

How to test a specific argument of a mocked PHPUnit method

My method has 3 arguments, but I just want to test the arg3, arg1 and arg2 don't matter:

$observer = $this->getMock('SomeObserverClass', array('myMethod'));
$observer->expects($this->once())
         ->method('myMethod')
         ->with(null, null, $this->equalTo($arg3));

Setting them to null or !$this->empty() does not work.

Signature of the method:

public function myMethod(Integer $arg1, String $arg2, String $arg3) {...}

Upvotes: 1

Views: 153

Answers (1)

Cyprian
Cyprian

Reputation: 11364

You can use anything matcher. Try:

$observer->expects($this->once())
     ->method('myMethod')
     ->with($this->anything(), $this->anything(), $this->equalTo($arg3));

Upvotes: 2

Related Questions