Skip to content

Commit 1de6a42

Browse files
author
Kostiantyn Poida
committed
MAGETWO-31363: Unit and Integration tests coverage
1 parent ad849eb commit 1de6a42

File tree

1 file changed

+70
-25
lines changed

1 file changed

+70
-25
lines changed

dev/tests/unit/testsuite/Magento/OfflineShipping/Model/Quote/FreeshippingTest.php

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,26 @@ protected function setUp()
3636
->setMethods([
3737
'getQuote',
3838
'getAllItems',
39-
'getFreeShipping'
39+
'getFreeShipping',
40+
'setFreeShipping'
4041
])
4142
->getMock();
4243

4344
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
4445
->disableOriginalConstructor()
4546
->getMock();
4647

48+
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
49+
->disableOriginalConstructor()
50+
->getMock();
51+
52+
$this->storeManagerMock->expects($this->once())
53+
->method('getStore')
54+
->willReturn($storeMock);
55+
4756
$this->calculatorMock = $this->getMockBuilder('Magento\OfflineShipping\Model\SalesRule\Calculator')
4857
->disableOriginalConstructor()
49-
//->setMethods(['init'])
58+
->setMethods(['init', 'processFreeShipping'])
5059
->getMock();
5160

5261
$this->model = $helper->getObject('Magento\OfflineShipping\Model\Quote\Freeshipping', [
@@ -75,59 +84,95 @@ public function testCollectWithEmptyAddressItems()
7584

7685
/**
7786
* @dataProvider scenariosDataProvider
87+
* @param $isNoDiscount
7888
*/
79-
public function testCollectWithAddressItems(
80-
$addressItemMockNoDiscountValue,
81-
$addressMockGetFreeShippingExpects
82-
) {
89+
public function testCollectWithAddressItems($isNoDiscount)
90+
{
8391
$quoteMock = $this->getMockBuilder('Magento\Sales\Model\Quote')
8492
->disableOriginalConstructor()
8593
->getMock();
8694

87-
$this->addressMock->expects($this->any())
95+
$this->addressMock->expects($this->once())
8896
->method('getQuote')
8997
->willReturn($quoteMock);
9098

9199
$addressItemMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address\Item')
92100
->disableOriginalConstructor()
93-
->setMethods(['getNoDiscount', 'getFreeShipping'])
101+
->setMethods([
102+
'getNoDiscount',
103+
'setFreeShipping',
104+
'getParentItemId',
105+
'getFreeShipping',
106+
'getHasChildren',
107+
'isChildrenCalculated',
108+
'getChildren'
109+
])
94110
->getMock();
95111

112+
$this->addressMock->expects($this->once())
113+
->method('getAllItems')
114+
->willReturn([$addressItemMock]);
115+
116+
$this->calculatorMock->expects($this->once())
117+
->method('init');
118+
96119
$addressItemMock->expects($this->once())
97120
->method('getNoDiscount')
98-
->willReturn($addressItemMockNoDiscountValue);
121+
->willReturn($isNoDiscount);
99122

100-
$addressItemMock->expects($this->any())
123+
$addressItemMock->expects($isNoDiscount ? $this->once() : $this->never())
124+
->method('setFreeShipping');
125+
126+
$addressItemMock->expects($isNoDiscount ? $this->never() : $this->once())
127+
->method('getParentItemId')
128+
->willReturn(false);
129+
130+
$this->calculatorMock->expects($isNoDiscount ? $this->never() : $this->exactly(2))
131+
->method('processFreeShipping');
132+
133+
$addressItemMock->expects($isNoDiscount ? $this->never() : $this->once())
101134
->method('getFreeShipping')
102135
->willReturn(true);
103136

104-
$this->addressMock->expects($addressMockGetFreeShippingExpects)
105-
->method('getFreeShipping')
106-
->willReturn(false);
137+
$addressItemMock->expects($isNoDiscount ? $this->never() : $this->once())
138+
->method('getHasChildren')
139+
->willReturn(true);
107140

108-
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
141+
$addressItemMock->expects($isNoDiscount ? $this->never() : $this->once())
142+
->method('isChildrenCalculated')
143+
->willReturn(true);
144+
145+
$childMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Item\AbstractItem')
109146
->disableOriginalConstructor()
147+
->setMethods(['setFreeShipping', 'getQuote', 'getAddress', 'getOptionByCode'])
110148
->getMock();
111149

112-
$this->storeManagerMock->expects($this->once())
113-
->method('getStore')
114-
->willReturn($storeMock);
150+
$addressItemMock->expects($isNoDiscount ? $this->never() : $this->once())
151+
->method('getChildren')
152+
->willReturn([$childMock]);
115153

116-
$this->calculatorMock->expects($this->once())
117-
->method('init');
154+
$childMock->expects($isNoDiscount ? $this->never() : $this->once())
155+
->method('setFreeShipping');
118156

119-
$this->addressMock->expects($this->once())
120-
->method('getAllItems')
121-
->willReturn([$addressItemMock]);
157+
$this->addressMock->expects($isNoDiscount ? $this->never() : $this->once())
158+
->method('getFreeShipping')
159+
->willReturn(false);
122160

123-
$this->model->collect($this->addressMock);
161+
$this->addressMock->expects($isNoDiscount ? $this->once() : $this->exactly(2))
162+
->method('setFreeShipping');
163+
164+
$this->assertSame($this->model->collect($this->addressMock), $this->model);
124165
}
125166

126167
public function scenariosDataProvider()
127168
{
128169
return [
129-
[true, $this->never()],
130-
[false, $this->once()]
170+
[
171+
true, // there is no a discount
172+
],
173+
[
174+
false, // there is a discount
175+
]
131176
];
132177
}
133178
}

0 commit comments

Comments
 (0)