Return empty collection when the cart is empty

This commit is contained in:
Rob Gloudemans
2016-06-15 09:59:03 +02:00
parent 9088f44e00
commit 13fe150b77
2 changed files with 15 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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()
{