I was creating a PHPUnit test and I needed to confirm that it never was sending an email given some conditions. The test where you check that the email is being called at least once is pretty simple, but how to do the opposite. A friend tipped me off and PHPUnit has $this->never() to be used instead of $this->once();
So basically is like this. If you need to test if its sending the email (or the method is being called):
$observer = $this->getMock('Observer', array('update'));
$observer->expects($this->once())
->method('update')
->with($this->equalTo('something'));
but if you need to test if the method is never being called just do:
$observer = $this->getMock('Observer', array('update'));
$observer->expects($this->never())
->method('update')
->with($this->equalTo('something'));
Pretty simple and logical. I haven’t still found that on the PHPUnit documentation, but I will stop by later again to see if I can find it.