title: Mock Middleware for route testing in Laravel
body: <p>I am trying to write some unit tests to ensure my routes are not accidentally rewritten. I found already an answer to check whether a correct controller is assigned to particular route <a href="https://stackoverflow.com/questions/29422426/how-to-test-routes-in-laravel-5-or-trying-to-mockstub-something-or-i-have-no">here</a>.</p>
  
  <p>However I would like to check as well that correct middlewares are assigned to route. I tried similar approach with</p>
  
  <pre><code>$tmp = new CorsService;
  $corsMiddleware = Mockery::mock('Barryvdh\Cors\HandleCors[handle]', array($tmp))
      -&gt;shouldReceive('handle')-&gt;once()
      -&gt;andReturnUsing(function($request, Closure $next) {
          return $next($request);
      });
  
  \App::instance('Barryvdh\Cors\HandleCors', $corsMiddleware);
  </code></pre>
  
  <p>For some reason the test is not picking this up. I am assuming that is because middleware instances are not stored using <code>App::instance</code>.</p>
  
  <p>What am I doing wrong?</p>