Skip to content

Commit ad849eb

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

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflineShipping\Model\Quote;
7+
8+
class FreeshippingTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflineShipping\Model\Quote\Freeshipping|\PHPUnit_Framework_MockObject_MockObject
12+
*/
13+
protected $model;
14+
15+
/**
16+
* @var \Magento\Sales\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $addressMock;
19+
20+
/**
21+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $storeManagerMock;
24+
25+
/**
26+
* @var \Magento\OfflineShipping\Model\SalesRule\Calculator|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $calculatorMock;
29+
30+
protected function setUp()
31+
{
32+
$helper = new \Magento\TestFramework\Helper\ObjectManager($this);
33+
34+
$this->addressMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address')
35+
->disableOriginalConstructor()
36+
->setMethods([
37+
'getQuote',
38+
'getAllItems',
39+
'getFreeShipping'
40+
])
41+
->getMock();
42+
43+
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
44+
->disableOriginalConstructor()
45+
->getMock();
46+
47+
$this->calculatorMock = $this->getMockBuilder('Magento\OfflineShipping\Model\SalesRule\Calculator')
48+
->disableOriginalConstructor()
49+
//->setMethods(['init'])
50+
->getMock();
51+
52+
$this->model = $helper->getObject('Magento\OfflineShipping\Model\Quote\Freeshipping', [
53+
'storeManager' => $this->storeManagerMock,
54+
'calculator' => $this->calculatorMock
55+
]);
56+
}
57+
58+
59+
public function testCollectWithEmptyAddressItems()
60+
{
61+
$quoteMock = $this->getMockBuilder('Magento\Sales\Model\Quote')
62+
->disableOriginalConstructor()
63+
->getMock();
64+
65+
$this->addressMock->expects($this->once())
66+
->method('getQuote')
67+
->willReturn($quoteMock);
68+
69+
$this->addressMock->expects($this->once())
70+
->method('getAllItems')
71+
->willReturn([]);
72+
73+
$this->assertSame($this->model->collect($this->addressMock), $this->model);
74+
}
75+
76+
/**
77+
* @dataProvider scenariosDataProvider
78+
*/
79+
public function testCollectWithAddressItems(
80+
$addressItemMockNoDiscountValue,
81+
$addressMockGetFreeShippingExpects
82+
) {
83+
$quoteMock = $this->getMockBuilder('Magento\Sales\Model\Quote')
84+
->disableOriginalConstructor()
85+
->getMock();
86+
87+
$this->addressMock->expects($this->any())
88+
->method('getQuote')
89+
->willReturn($quoteMock);
90+
91+
$addressItemMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address\Item')
92+
->disableOriginalConstructor()
93+
->setMethods(['getNoDiscount', 'getFreeShipping'])
94+
->getMock();
95+
96+
$addressItemMock->expects($this->once())
97+
->method('getNoDiscount')
98+
->willReturn($addressItemMockNoDiscountValue);
99+
100+
$addressItemMock->expects($this->any())
101+
->method('getFreeShipping')
102+
->willReturn(true);
103+
104+
$this->addressMock->expects($addressMockGetFreeShippingExpects)
105+
->method('getFreeShipping')
106+
->willReturn(false);
107+
108+
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
109+
->disableOriginalConstructor()
110+
->getMock();
111+
112+
$this->storeManagerMock->expects($this->once())
113+
->method('getStore')
114+
->willReturn($storeMock);
115+
116+
$this->calculatorMock->expects($this->once())
117+
->method('init');
118+
119+
$this->addressMock->expects($this->once())
120+
->method('getAllItems')
121+
->willReturn([$addressItemMock]);
122+
123+
$this->model->collect($this->addressMock);
124+
}
125+
126+
public function scenariosDataProvider()
127+
{
128+
return [
129+
[true, $this->never()],
130+
[false, $this->once()]
131+
];
132+
}
133+
}

0 commit comments

Comments
 (0)