@@ -38,10 +38,18 @@ class OrderTest extends \PHPUnit_Framework_TestCase
38
38
* @var \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject
39
39
*/
40
40
protected $ orderMock ;
41
+ /**
42
+ * @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject
43
+ */
44
+ protected $ orderItemMock ;
41
45
/**
42
46
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
43
47
*/
44
48
protected $ storeMock ;
49
+ /**
50
+ * @var \Magento\Store\Model\Website|\PHPUnit_Framework_MockObject_MockObject
51
+ */
52
+ protected $ websiteMock ;
45
53
/**
46
54
* @var \Magento\Store\Model\Group|\PHPUnit_Framework_MockObject_MockObject
47
55
*/
@@ -71,8 +79,28 @@ public function setUp()
71
79
{
72
80
$ this ->resourceMock = $ this ->getMock ('Magento\Framework\App\Resource ' , [], [], '' , false );
73
81
$ this ->orderMock = $ this ->getMock ('Magento\Sales\Model\Order ' , [], [], '' , false );
82
+ $ this ->orderItemMock = $ this ->getMock (
83
+ 'Magento\Sales\Model\Order\Item ' ,
84
+ ['getQuoteParentItemId ' , 'setTotalItemCount ' , 'getChildrenItems ' ],
85
+ [],
86
+ '' ,
87
+ false
88
+ );
74
89
$ this ->storeMock = $ this ->getMock ('Magento\Store\Model\Store ' , [], [], '' , false );
75
- $ this ->storeGroupMock = $ this ->getMock ('Magento\Store\Model\Group ' , [], [], '' , false );
90
+ $ this ->storeGroupMock = $ this ->getMock (
91
+ 'Magento\Store\Model\Group ' ,
92
+ ['getName ' , 'getDefaultStoreId ' ],
93
+ [],
94
+ '' ,
95
+ false
96
+ );
97
+ $ this ->websiteMock = $ this ->getMock (
98
+ 'Magento\Store\Model\Website ' ,
99
+ ['getName ' ],
100
+ [],
101
+ '' ,
102
+ false
103
+ );
76
104
$ this ->adapterMock = $ this ->getMock (
77
105
'Magento\Framework\DB\Adapter\Pdo\Mysql ' ,
78
106
[
@@ -138,7 +166,24 @@ public function setUp()
138
166
139
167
public function testSave ()
140
168
{
141
-
169
+ $ this ->orderMock ->expects ($ this ->exactly (3 ))
170
+ ->method ('getId ' )
171
+ ->willReturn (null );
172
+ $ this ->orderItemMock ->expects ($ this ->once ())
173
+ ->method ('getChildrenItems ' )
174
+ ->willReturn ([]);
175
+ $ this ->orderItemMock ->expects ($ this ->once ())
176
+ ->method ('getQuoteParentItemId ' )
177
+ ->willReturn (null );
178
+ $ this ->orderMock ->expects ($ this ->once ())
179
+ ->method ('setTotalItemCount ' )
180
+ ->with (1 );
181
+ $ this ->storeGroupMock ->expects ($ this ->once ())
182
+ ->method ('getDefaultStoreId ' )
183
+ ->willReturn (1 );
184
+ $ this ->orderMock ->expects ($ this ->once ())
185
+ ->method ('getAllItems ' )
186
+ ->willReturn ([$ this ->orderItemMock ]);
142
187
$ this ->orderMock ->expects ($ this ->once ())
143
188
->method ('validateBeforeSave ' )
144
189
->willReturnSelf ();
@@ -151,12 +196,15 @@ public function testSave()
151
196
$ this ->orderMock ->expects ($ this ->once ())
152
197
->method ('getEntityType ' )
153
198
->willReturn ('order ' );
154
- $ this ->orderMock ->expects ($ this ->once ( ))
199
+ $ this ->orderMock ->expects ($ this ->exactly ( 2 ))
155
200
->method ('getStore ' )
156
201
->willReturn ($ this ->storeMock );
157
- $ this ->storeMock ->expects ($ this ->once ( ))
202
+ $ this ->storeMock ->expects ($ this ->exactly ( 2 ))
158
203
->method ('getGroup ' )
159
204
->willReturn ($ this ->storeGroupMock );
205
+ $ this ->storeMock ->expects ($ this ->once ())
206
+ ->method ('getWebsite ' )
207
+ ->willReturn ($ this ->websiteMock );
160
208
$ this ->storeGroupMock ->expects ($ this ->once ())
161
209
->method ('getDefaultStoreId ' )
162
210
->willReturn (1 );
0 commit comments