title: How to mock a service (or a ServiceProvider) when running Feature tests in Laravel?
body: <p>I'm writing a small API in Laravel, partly for the purposes of learning this framework. I think I have spotted a gaping hole in the docs, but it may be due to my not understanding the "Laravel way" to do what I want.</p>
  
  <p>I am writing an HTTP API to, amongst other things, list, create and delete system users on a Linux server. The structure is like so:</p>
  
  <ul>
  <li>Routes to <code>/v1/users</code> connect <code>GET</code>, <code>POST</code> and <code>DELETE</code> verbs to controller methods <code>get</code>, <code>create</code> and <code>delete</code> respectively.</li>
  <li>The controller <code>App\Http\Controllers\UserController</code> does not actually run system calls, that is done by a service <code>App\Services\Users</code>.</li>
  <li>The service is created by a ServiceProvider <code>App\Providers\Server\Users</code> that registers a <code>singleton</code> of the service on a deferred basis.</li>
  <li>The service is instantiated by Laravel automatically and auto-injected into the controller's constructor.</li>
  </ul>
  
  <p>OK, so this all works. I have also written some test code, like so:</p>
  
  <pre><code>public function testGetUsers()
  {
      $response = $this-&gt;json('GET', '/v1/users');
      /* @var $response \Illuminate\Http\JsonResponse */
  
      $response
          -&gt;assertStatus(200)
          -&gt;assertJson(['ok' =&gt; true, ]);
  }
  </code></pre>
  
  <p>This also works fine. However, this uses the normal bindings for the <code>UserService</code>, and I want to put a dummy/mock in here instead.</p>
  
  <p>I think I need to change my <code>UserService</code> to an interface, which is easy, but I am not sure how to tell the underlying test system that I want it to run my controller, but with a non-standard service. I see <code>App::bind()</code> cropping up in Stack Overflow answers when researching this, but <code>App</code> is not automatically in scope in artisan-generated tests, so it feels like clutching at straws.</p>
  
  <p>How can I instantiate a dummy service and then send it to Laravel when testing, so it does not use the standard ServiceProvider instead?</p>