本文整理汇总了PHP中Observer::processCartUpdateBefore方法的典型用法代码示例。如果您正苦于以下问题:PHP Observer::processCartUpdateBefore方法的具体用法?PHP Observer::processCartUpdateBefore怎么用?PHP Observer::processCartUpdateBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Observer
的用法示例。
在下文中一共展示了Observer::processCartUpdateBefore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProcessCartUpdateBefore
/**
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testProcessCartUpdateBefore()
{
$customerId = 1;
$itemId = 5;
$itemQty = 123;
$productId = 321;
$eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
$event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getCart', 'getInfo'])->disableOriginalConstructor()->getMock();
$eventObserver->expects($this->exactly(2))->method('getEvent')->willReturn($event);
$quoteItem = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->setMethods(['getProductId', 'getBuyRequest', '__wakeup'])->disableOriginalConstructor()->getMock();
$buyRequest = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['setQty'])->disableOriginalConstructor()->getMock();
$infoData = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['toArray'])->disableOriginalConstructor()->getMock();
$infoData->expects($this->once())->method('toArray')->willReturn([$itemId => ['qty' => $itemQty, 'wishlist' => true]]);
$cart = $this->getMockBuilder('Magento\\Checkout\\Model\\Cart')->disableOriginalConstructor()->getMock();
$quote = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->setMethods(['getCustomerId', 'getItemById', 'removeItem', '__wakeup'])->disableOriginalConstructor()->getMock();
$event->expects($this->once())->method('getCart')->willReturn($cart);
$event->expects($this->once())->method('getInfo')->willReturn($infoData);
$cart->expects($this->any())->method('getQuote')->willReturn($quote);
$quoteItem->expects($this->once())->method('getProductId')->willReturn($productId);
$quoteItem->expects($this->once())->method('getBuyRequest')->willReturn($buyRequest);
$buyRequest->expects($this->once())->method('setQty')->with($itemQty)->willReturnSelf();
$quote->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$quote->expects($this->once())->method('getItemById')->with($itemId)->willReturn($quoteItem);
$quote->expects($this->once())->method('removeItem')->with($itemId);
$this->wishlist->expects($this->once())->method('loadByCustomerId')->with($this->logicalOr($customerId, true))->willReturnSelf();
$this->wishlist->expects($this->once())->method('addNewItem')->with($this->logicalOr($productId, $buyRequest));
$this->wishlist->expects($this->once())->method('save');
$this->helper->expects($this->once())->method('calculate');
/** @var $eventObserver \Magento\Framework\Event\Observer */
$this->assertSame($this->observer, $this->observer->processCartUpdateBefore($eventObserver));
}