Example #1
0
 /**
  * @covers \Magento\Shipping\Model\Shipping::composePackagesForCarrier
  */
 public function testComposePackages()
 {
     $this->carrier->expects($this->any())->method('getConfigData')->will($this->returnCallback(function ($key) {
         $configData = ['max_package_weight' => 10, 'showmethod' => 1];
         return isset($configData[$key]) ? $configData[$key] : 0;
     }));
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $product->expects($this->any())->method('getId')->will($this->returnValue($this->productId));
     $item = $this->getMockBuilder('\\Magento\\Sales\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['getProduct', 'getQty', 'getWeight', '__wakeup'])->getMock();
     $item->expects($this->any())->method('getProduct')->will($this->returnValue($product));
     $request = new RateRequest();
     $request->setData('all_items', [$item]);
     $request->setData('dest_postcode', 1);
     /** Testable service calls to CatalogInventory module */
     $this->stockItemService->expects($this->atLeastOnce())->method('getStockItem')->with($this->productId);
     $this->stockItemService->expects($this->atLeastOnce())->method('getEnableQtyIncrements')->with($this->productId)->will($this->returnValue(true));
     $this->stockItemService->expects($this->atLeastOnce())->method('getQtyIncrements')->with($this->productId)->will($this->returnValue(5));
     $this->stockItemData->expects($this->atLeastOnce())->method('getIsQtyDecimal')->will($this->returnValue(true));
     $this->stockItemData->expects($this->atLeastOnce())->method('getIsDecimalDivided')->will($this->returnValue(true));
     $this->carrier->proccessAdditionalValidation($request);
 }
Example #2
0
 /**
  * @covers \Magento\Shipping\Model\Shipping::composePackagesForCarrier
  */
 public function testComposePackages()
 {
     $request = new RateRequest();
     /** \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface */
     $item = $this->getMockBuilder('\\Magento\\Sales\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['getQty', 'getIsQtyDecimal', 'getProductType', 'getProduct', 'getWeight', '__wakeup'])->getMock();
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $item->expects($this->any())->method('getQty')->will($this->returnValue(1));
     $item->expects($this->any())->method('getWeight')->will($this->returnValue(10));
     $item->expects($this->any())->method('getIsQtyDecimal')->will($this->returnValue(true));
     $item->expects($this->any())->method('getProductType')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE));
     $item->expects($this->any())->method('getProduct')->will($this->returnValue($product));
     $product->expects($this->any())->method('getId')->will($this->returnValue($this->productId));
     $request->setData('all_items', [$item]);
     $this->stockItemData->expects($this->any())->method('getIsDecimalDivided')->will($this->returnValue(true));
     /** Testable service calls to CatalogInventory module */
     $this->stockItemService->expects($this->atLeastOnce())->method('getStockItem')->with($this->productId);
     $this->stockItemService->expects($this->atLeastOnce())->method('getEnableQtyIncrements')->with($this->productId)->will($this->returnValue(true));
     $this->stockItemService->expects($this->atLeastOnce())->method('getQtyIncrements')->with($this->productId)->will($this->returnValue(0.5));
     $this->shipping->composePackagesForCarrier($this->carrier, $request);
 }