Skip to content

Commit

Permalink
pint
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed Dec 6, 2024
1 parent f687216 commit 3fdf233
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/LaravelCartSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function getCart(?int $userId = null): array
*/
protected function sessionKey(int $userId): string
{
return self::SESSION_KEY_PREFIX . $userId;
return self::SESSION_KEY_PREFIX.$userId;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/Feature/Manager/Session/CartDeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

use Binafy\LaravelCart\LaravelCart;
use Binafy\LaravelCart\Models\Cart;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\SetUp\Models\Product;
use Tests\SetUp\Models\User;

use function Pest\Laravel\assertDatabaseCount;

test('can remove an item from the cart with facade', function () {
$user = User::query()->create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']);
auth()->login($user);
Expand Down
4 changes: 0 additions & 4 deletions tests/Feature/Manager/Session/CartStoreTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?php

use Binafy\LaravelCart\LaravelCart;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\SetUp\Models\Product;
use Tests\SetUp\Models\User;

use function Pest\Laravel\assertDatabaseCount;
use function Pest\Laravel\assertDatabaseHas;

afterEach(function () {
session()->flush();
});
Expand Down
16 changes: 6 additions & 10 deletions tests/Feature/Manager/Session/CartUpdateQuantityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

use Binafy\LaravelCart\LaravelCart;
use Binafy\LaravelCart\Models\Cart;
use Binafy\LaravelCart\Models\CartItem;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\SetUp\Models\Product;
use Tests\SetUp\Models\User;

use function Pest\Laravel\assertDatabaseHas;
use function Pest\Laravel\assertDatabaseMissing;

/*
* Use `RefreshDatabase` for delete migration data for each test.
*/
Expand Down Expand Up @@ -47,12 +43,12 @@
'quantity' => 3,
], 2);

expect(session("cart_2")[0]['quantity'])->toBe(3);
expect(session('cart_2')[0]['quantity'])->toBe(3);

// Increase quantity
LaravelCart::driver('session')->decreaseQuantity($product, 2, 2);

expect(session("cart_2")[0]['quantity'])->toBe(1);
expect(session('cart_2')[0]['quantity'])->toBe(1);
});

test('can not increase quantity of the item in cart with facade when item not found', function () {
Expand All @@ -68,12 +64,12 @@
'quantity' => 1,
], 2);

expect(session("cart_2")[0]['quantity'])->toBe(1);
expect(session('cart_2')[0]['quantity'])->toBe(1);

// Increase quantity
LaravelCart::driver('session')->increaseQuantity($product2, 2);

expect(session("cart_2")[0]['quantity'])->toBe(1);
expect(session('cart_2')[0]['quantity'])->toBe(1);
})->expectExceptionMessage('The item not found');

test('can not decrease quantity of the item in cart with facade when item not found', function () {
Expand All @@ -89,10 +85,10 @@
'quantity' => 3,
], 2);

expect(session("cart_2")[0]['quantity'])->toBe(3);
expect(session('cart_2')[0]['quantity'])->toBe(3);

// Decrease quantity
LaravelCart::driver('session')->decreaseQuantity($product2, 2);

expect(session("cart_2")[0]['quantity'])->toBe(3);
expect(session('cart_2')[0]['quantity'])->toBe(3);
})->expectExceptionMessage('The item not found');

0 comments on commit 3fdf233

Please sign in to comment.