mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
fix: serialize conditions to arrays before storage; type \$events
- serializeConditions() now maps CartCondition objects to arrays via
toArray() before passing to the driver, preventing json_encode()
producing {} for object values in the DatabaseDriver
- Add Dispatcher type hint to \$events property and constructor parameter
- Add database round-trip test for cart-level conditions
- Fix CartConditionsTest to retrieve condition objects from the cart
rather than relying on object-reference side-effects that no longer
hold after proper serialization
This commit is contained in:
@@ -112,6 +112,38 @@
|
||||
expect($this->cart->getTotal())->toEqual(18.45, 'Cart should have total of 18.45');
|
||||
});
|
||||
|
||||
test('cart-level conditions survive database round-trip', function () {
|
||||
$this->cart->condition(new CartCondition([
|
||||
'name' => 'GST',
|
||||
'type' => 'tax',
|
||||
'value' => '10%',
|
||||
'target' => 'subtotal',
|
||||
]));
|
||||
|
||||
// Create a fresh cart instance pointing at the same DB row
|
||||
$events2 = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||
$events2->shouldReceive('dispatch');
|
||||
|
||||
$cart2 = new \Wearepixel\Cart\Cart(
|
||||
new \Wearepixel\Cart\Drivers\DatabaseDriver(
|
||||
\Wearepixel\Cart\Tests\Helpers\MockCartModel::class,
|
||||
'session_id',
|
||||
'items',
|
||||
'conditions',
|
||||
'SAMPLESESSIONKEY',
|
||||
),
|
||||
$events2,
|
||||
'cart',
|
||||
require (__DIR__ . '/../Helpers/ConfigDatabaseMock.php')
|
||||
);
|
||||
|
||||
$condition = $cart2->getCondition('GST');
|
||||
|
||||
expect($condition)->not->toBeNull();
|
||||
expect($condition->getName())->toBe('GST');
|
||||
expect($condition->getValue())->toBe('10%');
|
||||
});
|
||||
|
||||
test('can clear a simple cart', function () {
|
||||
$this->cart->add(1, 'Sample Item', 100.99, 2, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user