title: Laravel integration testing jobs
body: <p>I am trying to run an integration tests for my app. I have those jobs:</p>
  
  <ul>
  <li>StartJob</li>
  <li>PrepareJob</li>
  <li>PeformJob</li>
  </ul>
  
  <p>StartJob dispatches one or more PrepareJob, every PrepareJob dispatches one PerformJob.</p>
  
  <p>Adding this </p>
  
  <pre><code>$this-&gt;expectsJobs(
          [
              StartJobs::class,
              PrepareJob::class,
              PerformJob::class
          ]
      );
  </code></pre>
  
  <p>makes my test fail with error saying </p>
  
  <pre><code>1) JobsTest::testJobs
  BadMethodCallException: Method Mockery_0_Illuminate_Contracts_Bus_Dispatcher::dispatchNow() does not exist on this mock object
  </code></pre>
  
  <p>Removing $this->expectsJobs makes all my tests pass, but I can't assert a given job was run, only whether it modified the DB to a given state.</p>
  
  <p>StartJobs.php</p>
  
  <pre><code>    class StartJobs extends Job implements ShouldQueue
      {
          use InteractsWithQueue;
          use DispatchesJobs;
  
          public function handle(Writer $writer)
          {
              $writer-&gt;info("[StartJob] Started");
  
              for($i=0; $i &lt; 5; $i++)
              {
                  $this-&gt;dispatch(new PrepareJob());
              }
  
              $this-&gt;delete();
          }
  
      }
  </code></pre>
  
  <p>PrepareJob.php</p>
  
  <pre><code>class PrepareJob  extends Job implements ShouldQueue
  {
      use InteractsWithQueue;
      use DispatchesJobs;
  
      public function handle(Writer $writer)
      {
          $writer-&gt;info("[PrepareJob] Started");
  
          $this-&gt;dispatch(new PerformJob());
  
          $this-&gt;delete();
      }
  
  }
  </code></pre>
  
  <p>PerformJob.php</p>
  
  <pre><code>class PerformJob  extends Job implements ShouldQueue
  {
      use InteractsWithQueue;
  
      public function handle(Writer $writer)
      {
          $writer-&gt;info("[PerformJob] Started");
  
          $this-&gt;delete();
      }
  }
  </code></pre>
  
  <p>JobsTest.php</p>
  
  <pre><code>class JobsTest extends TestCase
  {
      /**
       * @var Dispatcher
       */
      protected $dispatcher;
  
      protected function setUp()
      {
          parent::setUp();
          $this-&gt;dispatcher = $this-&gt;app-&gt;make(Dispatcher::class);
      }
  
      public function testJobs()
      {
          $this-&gt;expectsJobs(
              [
                  StartJobs::class,
                  PrepareJob::class,
                  PerformJob::class
              ]
          );
  
          $this-&gt;dispatcher-&gt;dispatch(new StartJobs());
      }
  }
  </code></pre>
  
  <p>I think it has to do something with how I am using a concrete dispatcher, while $this->expectsJob mocks the dispatcher. Might be related to this - <a href="https://github.com/laravel/lumen-framework/issues/207" rel="nofollow">https://github.com/laravel/lumen-framework/issues/207</a>. What's the way to solve this?</p>