title: Laravel Unit Testing Dependency Injection
body: <p>I'm trying to write a test class for a shopping cart. Here is what I have: </p>
  
  <p><em>ShoppingCartTest.php</em></p>
  
  <pre><code>class ShoppingCartTest extends TestCase {
  
      use DatabaseTransactions;
  
      protected $shoppingCart;
  
      public function __construct() {
          $this-&gt;shoppingCart = resolve('App\Classes\Billing\ShoppingCart');
      }
  
      /** @test */
      public function a_product_can_be_added_to_and_retrieved_from_the_shopping_cart() {
  
          // just a placeholder at the moment
          $this-&gt;assertTrue(true);
      }
  
  }
  </code></pre>
  
  <p>However, when I run phpunit, it seems like Laravel is unable to resolve my ShoppingCartClass.</p>
  
  <p>Here is the error:</p>
  
  <pre><code>Fatal error: Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException'
  with message 'Unresolvable dependency resolving
  [Parameter #0 [ &lt;required&gt; $app ]] in class Illuminate\Support\Manager'
  in C:\Development Server\EasyPHP-Devserver-16.1\eds-www\nrponline\vendor\laravel\framework\src\Illuminate\Container\Container.php:850
  </code></pre>
  
  <p>I have my ShoppingCart class being resolved in a number of different controllers just fine.</p>
  
  <p><strong>Why can't Laravel resolve it during my tests?</strong></p>
  
  <p>I refered to <a href="https://stackoverflow.com/questions/33363499/laravel-testing-service-dependency-injection-error">this post</a> as well but still didn't have any luck.</p>