123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Shipping\Test\Unit\Model;
- use \Magento\Shipping\Model\Shipping;
- use Magento\Quote\Model\Quote\Address\RateRequest;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
- class ShippingTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * Test identification number of product
- *
- * @var int
- */
- protected $productId = 1;
- /**
- * @var Shipping
- */
- protected $shipping;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Shipping\Model\Carrier\AbstractCarrier
- */
- protected $carrier;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $stockRegistry;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $stockItemData;
- protected function setUp()
- {
- $this->carrier = $this->createMock(\Magento\Shipping\Model\Carrier\AbstractCarrier::class);
- $this->carrier->expects($this->any())->method('getConfigData')->will($this->returnCallback(function ($key) {
- $configData = [
- 'max_package_weight' => 10,
- ];
- return isset($configData[$key]) ? $configData[$key] : 0;
- }));
- $this->stockRegistry = $this->createMock(\Magento\CatalogInventory\Model\StockRegistry::class);
- $this->stockItemData = $this->createMock(\Magento\CatalogInventory\Model\Stock\Item::class);
- $objectManagerHelper = new ObjectManagerHelper($this);
- $this->shipping = $objectManagerHelper->getObject(
- \Magento\Shipping\Model\Shipping::class,
- ['stockRegistry' => $this->stockRegistry]
- );
- }
- /**
- * @covers \Magento\Shipping\Model\Shipping::composePackagesForCarrier
- */
- public function testComposePackages()
- {
- $request = new RateRequest();
- /** \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface */
- $item = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)
- ->disableOriginalConstructor()
- ->setMethods([
- 'getQty', 'getIsQtyDecimal', 'getProductType', 'getProduct', 'getWeight', '__wakeup', 'getStore',
- ])
- ->getMock();
- $product = $this->createMock(\Magento\Catalog\Model\Product::class);
- $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));
- $store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getWebsiteId']);
- $store->expects($this->any())
- ->method('getWebsiteId')
- ->will($this->returnValue(10));
- $item->expects($this->any())->method('getStore')->will($this->returnValue($store));
- $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->stockRegistry->expects($this->atLeastOnce())->method('getStockItem')
- ->with($this->productId, 10)
- ->will($this->returnValue($this->stockItemData));
- $this->stockItemData->expects($this->atLeastOnce())
- ->method('getEnableQtyIncrements')
- ->will($this->returnValue(true));
- $this->stockItemData->expects($this->atLeastOnce())->method('getQtyIncrements')
- ->will($this->returnValue(0.5));
- $this->shipping->composePackagesForCarrier($this->carrier, $request);
- }
- }
|