public function add(Product $product, int $quantity)
{
if (!$product->isAvailable()) {
throw new ProductNotAvailableException($product);
}
if (!$product->price()->hasCurrency($this->currency)) {
throw new InvalidCurrencyException($this->currency, $product->price()->currency());
}
if (array_key_exists((string) $product->sku(), $this->items)) {
$quantity += $this->items[(string) $product->sku()]->quantity();
}
$this->items[(string) $product->sku()] = new CartItem($product->sku(), $quantity);
}
function it_can_be_used_to_place_order(Products $products, Carts $carts) { $product = new Product(new SKU("SKU"), Price::EUR(1000), true); $cart = new Cart(CartId::generate(), 'EUR'); $cart->add($product, 1); $carts->getById(Argument::type(CartId::class))->willReturn($cart); $products->getBySku(Argument::type(SKU::class))->willReturn($product); $order = $this->placeOrder(OrderId::generate(), $products, $carts); $order->shouldBeAnInstanceOf(Order::class); }