6 declare(strict_types=1);
17 use PHPUnit_Framework_MockObject_MockObject as MockObject;
21 private static $websiteId = 1;
23 private static $customerGroupId = 2;
25 private static $couponCode = 3;
27 private static $storeId = 1;
37 private $storeManager;
46 $this->storeManager = $this->createMock(StoreManagerInterface::class);
47 $this->calculator = $this->createMock(Calculator::class);
64 public function testIsFreeShipping(
int $addressFree,
int $fItemFree,
int $sItemFree,
bool $expected)
66 $address = $this->getShippingAddress();
69 $fItem = $this->getItem(
$quote);
70 $sItem = $this->getItem(
$quote);
73 $this->calculator->method(
'init')
75 $this->calculator->method(
'processFreeShipping')
80 ->willReturnCallback(
function () use ($fItem, $sItem, $addressFree, $fItemFree, $sItemFree) {
82 $fItem->getAddress()->setFreeShipping($addressFree);
83 $fItem->setFreeShipping($fItemFree);
84 $sItem->setFreeShipping($sItemFree);
88 self::assertEquals($expected, $actual);
89 self::assertEquals($expected,
$address->getFreeShipping());
100 [
'addressFree' => 1,
'fItemFree' => 0,
'sItemFree' => 0,
'expected' =>
true],
101 [
'addressFree' => 0,
'fItemFree' => 1,
'sItemFree' => 0,
'expected' =>
false],
102 [
'addressFree' => 0,
'fItemFree' => 0,
'sItemFree' => 1,
'expected' =>
false],
103 [
'addressFree' => 0,
'fItemFree' => 1,
'sItemFree' => 1,
'expected' =>
true],
110 private function withStore()
112 $store = $this->getMockBuilder(StoreInterface::class)
113 ->disableOriginalConstructor()
115 $this->storeManager->method(
'getStore')
119 $store->method(
'getWebsiteId')
129 private function getQuote(Address
$address): Quote
132 $quote = $this->getMockBuilder(Quote::class)
133 ->disableOriginalConstructor()
136 'getCouponCode',
'getCustomerGroupId',
'getShippingAddress',
'getStoreId',
'getItemsQty',
142 $quote->method(
'getStoreId')
144 $quote->method(
'getCustomerGroupId')
145 ->willReturn(self::$customerGroupId);
146 $quote->method(
'getCouponCode')
148 $quote->method(
'getShippingAddress')
150 $quote->method(
'getItemsQty')
152 $quote->method(
'getVirtualItemsQty')
163 private function getShippingAddress(): Address
166 $address = $this->getMockBuilder(Address::class)
167 ->disableOriginalConstructor()
168 ->setMethods([
'beforeSave'])
180 private function getItem(Quote
$quote): Item
183 $item = $this->getMockBuilder(Item::class)
184 ->disableOriginalConstructor()
185 ->setMethods([
'getHasChildren'])
188 $item->setNoDiscount(0);
189 $item->setParentItemId(0);
190 $item->method(
'getHasChildren')
testIsFreeShipping(int $addressFree, int $fItemFree, int $sItemFree, bool $expected)