title: Why I cannot assert that the job has been dispatched?
body: <p>I have the following Laravel Controller:</p>
  <pre><code>namespace App\Controller;
  
  use App\Jobs\MyJob;
  
  class JobDispatchControler
  {
     public function callJob(Request $request)
     {
       MyJob::dispatch();
     }
  }
  
  </code></pre>
  <p>The controller above has the following route:</p>
  <pre><code>Route::get('/job',&quot;\App\Controller\JobDispatchControler@callJob&quot;);
  </code></pre>
  <p>And I want to test whether I a call to the <code>/job</code> will dispatch the <code>MyJob</code> job:</p>
  <pre><code>namespace Test\App\MyJob;
  
  use Illuminate\Foundation\Testing\TestCase;
  use Illuminate\Support\Facades\Queue;
  use App\Jobs\MyJob;
  
  class TestDispatchJob extends TestCase
  {
     public function testJobDispatch()
     {
       Queue::fake();
       self::get(&quot;/job&quot;);
       Queue::assertPushed(MyJob::class);
     }
  }
  </code></pre>
  <p>But Once I run via phpunit the test I get the following error:</p>
  <pre><code>Time: 4.63 seconds, Memory: 34.00 MB
  
  There was 1 failure:
  
  1) Test\App\MyJob::testJobDispatch
  The expected [App\Jobs\MyJob] job was not pushed.
  
  /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/QueueFake.php:33
  /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237
  /var/www/html/tests/App/MyJob/TestDispatchJob.php:26
  
  FAILURES!
  Tests: 1, Assertions: 1, Failures: 1.
  
  </code></pre>
  <p>Do you know why I fail to assert that my job jas not been dispatched?</p>
  <h1>Edit 1</h1>
  <p>According to this <a href="https://medium.com/the-andela-way/mock-testing-in-laravel-4a2fe15885b8" rel="noreferrer">article</a> I changed my test into:</p>
  <pre><code>namespace Test\App\MyJob;
  
  use Illuminate\Foundation\Testing\TestCase;
  use Illuminate\Support\Facades\Bus;
  use App\Jobs\MyJob;
  
  class TestDispatchJob extends TestCase
  {
     public function testJobDispatch()
     {
       Bus::fake();
       self::get(&quot;/job&quot;);
       Bus::assertDispatched(MyJob::class);
     }
  }
  </code></pre>
  <p>And still get the following error:</p>
  <pre><code>FAILURES!
  Tests: 1, Assertions: 1, Failures: 1.
  
  Time: 4.63 seconds, Memory: 34.00 MB
  
  There was 1 failure:
  
  1) Test\App\MyJob::testJobDispatch
  The expected [App\Jobs\MyJob] job was not dispatched.
  
  /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/BusFake.php:32
  /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237
  /var/www/html/tests/App/MyJob/TestDispatchJob.php:26
  
  FAILURES!
  Tests: 1, Assertions: 1, Failures: 1.
  </code></pre>
  <p>But once instead of triggering the <code>get</code> method arbitary dispach the job seems to work ok:</p>
  <pre><code>namespace Test\App\MyJob;
  
  use Illuminate\Foundation\Testing\TestCase;
  use Illuminate\Support\Facades\Bus;
  use App\Jobs\MyJob;
  
  class TestDispatchJob extends TestCase
  {
     public function testJobDispatch()
     {
       Bus::fake();
       MyJob::dispatch();
       Bus::assertDispatched(MyJob::class);
     }
  }
  </code></pre>