I\'ve run into a strange issue with PHPUnit mock objects. I have a method that should be called twice, so I\'m using the \"at\" matcher. This works for the first time the method
This is an unfortunate wording of the error message by PHPUnit.
Double check the order of your calls, like @rr's answer mentions.
For me, as far as I know with my own code, I should be using at(0)
and at(1)
respectively, but it wasn't until I used at(2)
and at(3)
instead that it worked. (I'm using session mocking in CakePHP.)
The best way to check the order is to get 'into' the called method and check what's passed. You can do that like this:
$cakePost = $this->getMock('CakePost');
$cakePost->expects($this->once())
->method('post')
->with(
// Add a line like this for each arg passed
$this->callback(function($arg) {
debug("Here's what was passed: $arg");
})
);