title: Mockery: Method does not exist on mock object
body: <p>So I have an object which I am mocking and it has methods that are used for sending emails.  I have gone from a static class over to a concrete class because I was having issues testing the static class with Mockery.</p>
  
  <p>However I am now finding that when an eloquent model is saved it throws an event which fires off a listener.  This listener is what is responsible for kicking off the call to the mock objects method.</p>
  
  <p>I have found that when I do something like the following it works.</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>$model = factory(MyClass::class)-&gt;make();
  $model-&gt;property = 'value';
  $model-&gt;save()
  $this-&gt;mailer-&gt;shouldHaveReceived('methodName')-&gt;with($arg1, $arg2, $arg3);
  </code></pre>
  
  <p>It will fail every time complaining that the method does not exist on the mock object, the worst part is if I go into my listener where the mock object method is called and I do something like this</p>
  
  <pre class="lang-php prettyprint-override"><code>echo '&lt;pre&gt;'.print_r(get_class_methods($this-&gt;mailer), true).'&lt;/pre&gt;'; exit;
  </code></pre>
  
  <p>it shows that the method is in-fact in the array of methods returned from get_class_methods.</p>
  
  <p>Now here is the kicker.  Everything works perfectly and the test passes without any errors if I do the following:</p>
  
  <pre class="lang-php prettyprint-override"><code>$this-&gt;mailer-&gt;shouldReceive('methodName');
  $model = factory(MyClass::class)-&gt;make();
  $model-&gt;property = 'value';
  $model-&gt;save()
  </code></pre>
  
  <p>Now I have been reading the <a href="http://docs.mockery.io/en/latest/reference/mockery/gotchas.html" rel="nofollow">Mockery Gotchas</a> and it would appear that if my class was calling a method that truly didn't exist on the object via <code>___call</code> then this error would be expected.</p>
  
  <p>However my mailer class is NOT extending any other class that would have a <code>__call</code> method nor does it have that method defined on the class.</p>
  
  <p>However as you may or may not know Eloquent Models do in-fact use the magic <code>___call</code> method.  However I am NOT mocking the model with Mockery, I am using factory models in Laravel but I am also not checking the model object for the method call, I am checking my concrete mailer class for the method call.</p>
  
  <p>Anyone know why I might be getting this behavior from Mockery?</p>
  
  <p>I am creating my mock object in Laravel 5.2 with the following code</p>
  
  <pre class="lang-php prettyprint-override"><code>public function mock($class)
  {
      $mock = Mockery::mock($class);
      $this-&gt;app-&gt;instance($class, $mock);
      return $mock;
  }
  
  $this-&gt;mailer = $this-&gt;mock('Namespace\Classname');
  </code></pre>