diff --git a/src/Cart.php b/src/Cart.php index 82960a8..89efeb9 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -205,6 +205,10 @@ class Cart */ public function content() { + if (is_null($this->session->get($this->instance))) { + return new Collection([]); + } + return $this->session->get($this->instance); } diff --git a/tests/CartTest.php b/tests/CartTest.php index 7edc9d9..6c17eca 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -446,6 +446,17 @@ class CartTest extends Orchestra\Testbench\TestCase $this->assertCount(2, $content); } + /** @test */ + public function it_will_return_an_empty_collection_if_the_cart_is_empty() + { + $cart = $this->getCart(); + + $content = $cart->content(); + + $this->assertInstanceOf(\Illuminate\Support\Collection::class, $content); + $this->assertCount(0, $content); + } + /** @test */ public function it_can_destroy_a_cart() {