title: Mocking IOC container for Laravel package test
body: <p>I'm working on a package that interacts with the current request to retrieve information. To retrieve that information, I use <code>$request = Container::getInstance()-&gt;make('request');</code>.</p>
  
  <p>It works perfect when I use it in a Laravel application. However, I'm trying to get full code coverage in my tests. I believe I need to create a new Container object and pass it a request for my test, but it's not working out so great. Here's what I'm doing...</p>
  
  <pre><code>/**
   * Create a mock request
   *
   * @return Illuminate\Http\Request
   */
  public function createDummyRequest($headers = [], $payload = null): Request
  {
      return new Request([], [], [], [], [], $headers, $payload);
  }
  
  /**
   * Create a dummy IOC container
   *
   * @return Illuminate\Container\Container
   */
  public function createDummyContainer(): Container
  {
      return new Container;
  }
  
  /** @test */
  public function response_preferred_format_returns_xml()
  {
      $container = $this-&gt;createDummyContainer();
  
      $request = $this-&gt;createDummyRequest(['Accept' =&gt; 'application/json'], json_encode($this-&gt;testArray));
  
      $container-&gt;instance('request', $request);
  
      $response = $this-&gt;createDummyResponse()-&gt;preferredFormat($this-&gt;testArray, 200, ['Accept' =&gt; 'application/xml']);
  
      $this-&gt;assertEquals($this-&gt;testXml, $response-&gt;getContent());
  }
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>ReflectionException: Class request does not exist
  </code></pre>
  
  <p>Am I on the right track, or am I missing something obvious? Why can't I instantiate the <code>Container</code> class and bind an instance of <code>Request</code> so my code can utilize it?</p>