#!/usr/bin/env php getId() . "\n\n"; // Test addItem() method echo "Testing addItem() method...\n"; $result = $cart->addItem('product-1', 'Test Product', 29.99, 2); echo " ✓ addItem() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n"; echo " - Items count: " . count($result['items']) . "\n\n"; // Test updateQuantity() method $cart2 = new ShoppingCartComponent( id: 'cart-test-2', initialData: ['items' => [[ 'id' => 'item-1', 'product_id' => 'product-1', 'product_name' => 'Test Product', 'price' => 29.99, 'quantity' => 2, 'attributes' => [], 'added_at' => time(), 'updated_at' => time(), ]]] ); echo "Testing updateQuantity() method...\n"; $result = $cart2->updateQuantity('item-1', 5); echo " ✓ updateQuantity() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n"; echo " - New quantity: " . $result['items'][0]['quantity'] . "\n\n"; // Test applyDiscountCode() method echo "Testing applyDiscountCode() method...\n"; $result = $cart->applyDiscountCode('WELCOME10'); echo " ✓ applyDiscountCode() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n"; echo " - Discount code: " . ($result['discount_code'] ?? 'none') . "\n"; echo " - Discount percentage: " . $result['discount_percentage'] . "\n\n"; // Test removeDiscountCode() method echo "Testing removeDiscountCode() method...\n"; $result = $cart->removeDiscountCode(); echo " ✓ removeDiscountCode() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n"; echo " - Discount code: " . ($result['discount_code'] ?? 'null') . "\n\n"; // Test changeShippingMethod() method echo "Testing changeShippingMethod() method...\n"; $result = $cart->changeShippingMethod('express'); echo " ✓ changeShippingMethod() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n"; echo " - Shipping method: " . $result['shipping_method'] . "\n\n"; // Test clearCart() method echo "Testing clearCart() method...\n"; $result = $cart->clearCart(); echo " ✓ clearCart() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n"; echo " - Items count: " . count($result['items']) . "\n\n"; echo "========================================\n"; echo "✅ All ShoppingCartComponent tests passed!\n"; } catch (\Throwable $e) { echo "❌ Error: " . $e->getMessage() . "\n"; echo " File: " . $e->getFile() . ":" . $e->getLine() . "\n"; exit(1); }