title: Mocking Eloquent model with Mockery on Laravel (Lumen) doesn't work
body: <p>Pretty new to PHP, so forgive me if I missed something obvious.</p>
  
  <p>I'm currently using Lumen (which is basically a basic Laravel, with only core dependencies) and Eloquent to manage persistent entities.</p>
  
  <p>I want to write a Unit Test where I need to call a function which, at some point do an Eloquent query like this : </p>
  
  <pre><code>$errorMailRecipients = User::where('id_role',  1)
          -&gt;where('some_value', 1)
          -&gt;whereNotNull('email_addr');
  </code></pre>
  
  <p>My User.class, is a basic Eloquent entity : </p>
  
  <pre><code>    class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
      {
         use Authenticatable, Authorizable, Eloquence, Mappable;
  
         const CREATED_AT = 'creation_date';
         const UPDATED_AT = 'modification_date';
  
         /** Eloquent model configuration */
         protected $connection = 'database_name';
         protected $table = 'user';
         protected $primaryKey = 'id';
  
        // other stuff mapping, functions, etc ...
  }
  </code></pre>
  
  <p>So, I created a test and trying, with Mockery, to mock this specific query :</p>
  
  <pre><code>class ImportTest extends TestCase
  {
  
      public function test_should_send_error_mail_when_receiving_empty_request()
      {
          // Given
          $controller = new ImportController();
  
          $mockedRecipients = // &lt;- some Collection containing static data
          $mock = Mockery::mock(User::class, function ($mock) use ($mockedRecipients) {
              $mock-&gt;shouldReceive('where')-&gt;once()-&gt;andReturn($mockedRecipients);
          });
          $this-&gt;app-&gt;instance('App\Models\User', $mock);
  
          // When
          $controller-&gt;importDevices(new Request());
  
          // Then
      }
   }
  </code></pre>
  
  <p>I tried many variants, and to decompose mocking into multiple lines : </p>
  
  <pre><code>    $mock = Mockery::mock(User::class);
      $this-&gt;app-&gt;instance('User', $mock);
      $mock-&gt;shouldReceive('where')-&gt;once()-&gt;andReturn($mockedRecipients);
  </code></pre>
  
  <p>Also tried to remove the ->once(), and read the following guides : </p>
  
  <ul>
  <li><a href="https://laravel.com/docs/5.8/mocking" rel="nofollow noreferrer">https://laravel.com/docs/5.8/mocking</a></li>
  <li><a href="http://docs.mockery.io/en/latest/reference/alternative_should_receive_syntax.html" rel="nofollow noreferrer">http://docs.mockery.io/en/latest/reference/alternative_should_receive_syntax.html</a></li>
  </ul>
  
  <p>But so far, I kept having the following error when executing PHP Unit test : </p>
  
  <blockquote>
    <p>Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection refused ...</p>
  </blockquote>
  
  <p>Because, yeah, I don't have local database and it's still trying to hit it. Any thoughts ?
  Thank you</p>