title: Mockery and Laravel constructor injection
body: <p>I am using laravel 5 with php unit to create a laravel package. I have a <code>Repository</code>..</p>
  
  <pre><code>namespace Myname\Myapp\Repositories;
  
  use Myname\Myapp\Models\PersonModel;
  
  class PersonRepository
  {
      protected $personModel;
  
      public function __construct(PersonModel $personModel)
      {
          $this-&gt;personModel = $personModel;
      }
  
      public function testFunction($var)
      {
          return $this-&gt;personModel-&gt;find($var);
      }
  }
  </code></pre>
  
  <p>..which implements a <code>Model</code>.</p>
  
  <pre><code>namespace Myname\Myapp\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class PersonModel extends Model
  {
      protected $table = 'person';
  }
  </code></pre>
  
  <p>Laravels IoC automatically injects <code>PersonModel</code> into the constructor of <code>PersonRepository</code>.</p>
  
  <p>I am writing a unit test where I want to mock the <code>PersonModel</code> model using mockery so I am not hitting the database during testing.</p>
  
  <pre><code>namespace Myname\Myapptests\unit;
  
  use Mockery;
  
  class PersonRepositoryTest extends \Myname\Myapptests\TestCase
  {
       /**
       * @test
       */ 
       public function it_returns_the_test_find()
       {
           $mock = Mockery::mock('Myname\Myapp\Models\PersonModel')
              -&gt;shouldReceive('find')
              -&gt;with('var');
  
           $this-&gt;app-&gt;instance('Myname\Myapp\Models\PersonModel', $mock);
           $repo = $this-&gt;app-&gt;make('Myname\Myapp\Repositories\PersonRepository');
           $result = $repo-&gt;testFunction('var');
  
           $this-&gt;assert...
       }
  }
  </code></pre>
  
  <p>When I run the test I get an error </p>
  
  <blockquote>
    <p>1) Myname\Myapptests\unit\PersonRepositoryTest::it_returns_the_test_find
    ErrorException: Argument 1 passed to Myname\Myapp\Repositories\PersonRepository::__construct() must be an instance of Myname\Myapp\Models\PersonModel, instance of Mockery\CompositeExpectation given</p>
  </blockquote>
  
  <p>From what I have read, mockery extends the class it is mocking so there should be no issue injecting the extended class in place of the type hinted parent (PersonModel)</p>
  
  <p>Obviously I am missing something. Other examples explicitly inject the mocked object into the class they are then testing. Laravels IoC is (should be) doing this for me. Do I have to bind anything?</p>
  
  <p>I have a feeling though that the mockery object isn't being created in the way I think (extending PersonModel) otherwise I assume I wouldn't see this error.</p>