mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-21 23:05:05 +00:00
Return empty collection when the cart is empty
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user