title: How to mock Laravel model for a test of a class?
body: <p>I have a class like this:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
  use App\Models\Product;
  
  class ProductSearcher
  {
      public function getPrintedProducts( $releasedOnly = true ) {
          $products = Product::with('productVersion','productVersion.tag')
                        -&gt;where('printed', 1);
          if ($releasedOnly)
              $products-&gt;where('released', 1);
          $products = $products-&gt;get();
          return $products;
      }
  }
  </code></pre>
  <p>In my testing, I write</p>
  <pre class="lang-php prettyprint-override"><code>// ... some other testing ...
  public function testChossingCorrectingProductFromProductVersionIds()
  {
      $productSearcher= new ProductSearcher;
  
      $productMock = \Mockery::mock( 'App\Models\Product' );
      $productMock-&gt;shouldReceive( 'with-&gt;where-&gt;where-&gt;get' )-&gt;andReturn( [] );
  
      $this-&gt;assertEmpty( $productSearcher-&gt;getPrintedProducts( true ) );
  }
  // ... some other testing ...
  </code></pre>
  <p>I run the test but get:</p>
  <pre><code>PHP Fatal error:  Cannot redeclare Mockery_1_App_Models_Product::mockery_init()
  </code></pre>
  <p>May I ask what have I done wrong? Or what is the proper way to test this function? (It is a unit test that should not be too heavy, so connecting to a testing database is not an option)</p>