public function testReplaceCartItemsChildrenReplacesAllChildCartItemsWithNewItemsBuiltFromFlatOptions() { $flatOptions = array(22 => 33); $cartItem = $this->getMock('\\SpeckCart\\Entity\\CartItem'); $cartItem->expects($this->any())->method('getCartItemId')->will($this->returnValue(1)); $meta = $this->getMock('SpeckCatalog\\Model\\CartItemMeta'); $meta->expects($this->any())->method('getProductId')->will($this->returnValue('99')); $meta->expects($this->any())->method('setFlatOptions')->with($flatOptions); $childCartItem = $this->getMock('\\SpeckCart\\Entity\\CartItem'); $childCartItem->expects($this->any())->method('getCartItemId')->will($this->returnValue(8)); $items = array($childCartItem); $cartItem->expects($this->any())->method('getItems')->will($this->returnValue($items)); $cartItem->expects($this->any())->method('getMetadata')->will($this->returnValue($meta)); $mockCart = $this->getMock('\\SpeckCart\\Entity\\Cart'); $mockCart->expects($this->any())->method('getItems')->will($this->returnValue(array($cartItem))); $mockSpeckCartService = $this->getMock('\\SpeckCart\\Service\\CartService'); $mockSpeckCartService->expects($this->once())->method('getSessionCart')->will($this->returnValue($mockCart)); $choice1 = new \SpeckCatalog\Model\Choice\Relational(); $choice1->setChoiceId(33); $option = new \SpeckCatalog\Model\Option\Relational(); $option->setOptionId(22)->setChoices(array($choice1)); $product = new \SpeckCatalog\Model\Product\Relational(); $product->setOptions(array($option)); $mockProductService = $this->getMock('\\SpeckCatalog\\Service\\Product'); $mockProductService->expects($this->any())->method('getFullProduct')->will($this->returnValue($product)); $service = $this->getService(); $service->setCartService($mockSpeckCartService); $service->setProductService($mockProductService); $mockSpeckCartService->expects($this->once())->method('removeItemFromCart')->with(8); $mockSpeckCartService->expects($this->once())->method('addItemToCart'); $mockSpeckCartService->expects($this->once())->method('persistItem'); $service->replaceCartItemsChildren(1, $flatOptions); }