title: Mocking a Laravel Command Dependency
body: <p>As the official Laravel's <a href="https://laravel.com/docs/5.7/artisan#command-structure" rel="nofollow noreferrer">documentation</a> says so I made the following command:</p>
  
  <pre><code>namespace App\Console\Commands;
  
  use App\Model\Report;
  use Illuminate\Console\Command;
  use Exception;
  
  class ExportAnualReport extends Command
  {
      /**
       * @var string
       */
      protected $description = "Print Anual Report";
  
      /**
       * @var string
       */
      protected $signature = "report:anual";
  
      public function __construct()
      {
          parent::__construct();
      }
  
      public function handle(Report $report): int
      {
          //@todo Implement Upload
          try {
              $reportData = $report-&gt;getAnualReport();
              $this-&gt;table($reportData['headers'], $reportData['data']);
              return 0;
          } catch (Exception $e) {
              $this-&gt;error($e-&gt;getMessage());
              return 1;
          }
      }
  }
  </code></pre>
  
  <p>But instead of the approach used in this <a href="https://stackoverflow.com/q/56853267/4706711">question</a>  I already follow laravel's approach and recommendation and I utilize Dependency Injection in order to insert my model as a Service.</p>
  
  <p>So I the meantime I thought it would be a good Idea to Unit test it:</p>
  
  <pre><code>namespace Tests\Command;
  
  use App\Model\Report;
  use Tests\TestCase;
  
  class TripAdvisorUploadFeedCommandTest extends TestCase
  {
      public function setUp()
      {
          parent::setUp();
      }
  
      public function testFailAnualReport()
      {
          $this-&gt;artisan('report:anual')-&gt;assertExitCode(1);
      }
  
      public function testSucessAnualReport()
      {
          $this-&gt;artisan('report:anual')-&gt;assertExitCode(0);
      }
  }
  </code></pre>
  
  <p>But In my case I already have inject the Eloquent Model <code>Report</code> into my command via the <code>handle</code> function, so I want to mock the <code>Report</code> object instance Instead of hitting the actual database. </p>
  
  <p>For the record the <code>Report</code> Object is the following:</p>
  
  <pre><code>namespace App\Model
  
  use Illuminate\Database\Eloquent\Model;
  use Carbon\Carbon
  use Illuminate\Database\Eloquent\ModelNotFoundException;
  
  class Report extends Model
  {
       /**
       * @var string
       */
      protected $table = 'myapp_report_records';
  
      /**
       * @var string
       */
      protected $primaryKey = 'report_id';
  
      public function getAnualReport()
      {
          $now=Carbon::now();
          $oneYearBefore=new Carbon($now);
          $oneYearBefore-&gt;modify('-1 year');
  
          $results=$this-&gt;where('date','&gt;',$oneYearBefore)-&gt;where('date','&lt;',$now)-&gt;all();
  
          if(empty($results)){
              throw new ModelNotFoundException();
          }
  
          return $results;
      }
  }
  </code></pre>
  
  <p>So how I can mock the provided <code>Report</code> model?</p>