Not sure why I am receiving this error, spent too much time trying to figure it out. My test case:
public function test_cart_total_price_updates_upon_removing_a_product()
{
$user = User::factory()->create();
$carts = Cart::factory()->count(4)->create(['user_id' => $user->id]);
$this->actingAs($user);
$response = $this->get('/cart');
$response->assertStatus(200);
// Get the total cart price
$cartTotal = CartController::getTotalCartPrice();
// Make sure the total price is shown in the cart page
$response->assertSee($cartTotal);
// Get 1 cart that matches with user
$cart = Cart::where('user_id', $user->id)->first();
// Delete a cart
$response = $this->post('cart.destroy', [$cart]);
$response->assertRedirect('/cart');
}
Route
Route::resource('/cart', CartController::class);
Controller
public function destroy(Cart $cart)
{
$cart->delete();
return redirect()->route('cart.index')->with('alert', 'Deleted product from cart');
}