PHPUnit how to test when the method is never invoked

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'));

but if you need to test if the method is never being called just do:

  $observer = $this->getMock('Observer', array('update'));

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.


About mcloide

Making things simpler, just check: View all posts by mcloide

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: