@@ -43,6 +43,11 @@ class BundleSaveOptionsTest extends \PHPUnit_Framework_TestCase
43
43
*/
44
44
protected $ productBundleOptionsMock ;
45
45
46
+ /**
47
+ * @var \PHPUnit_Framework_MockObject_MockObject
48
+ */
49
+ protected $ productInterfaceFactoryMock ;
50
+
46
51
/**
47
52
* @var \Closure
48
53
*/
@@ -62,7 +67,12 @@ protected function setUp()
62
67
$ this ->closureMock = function () {
63
68
return $ this ->productMock ;
64
69
};
65
- $ this ->plugin = new BundleSaveOptions ($ this ->productOptionRepositoryMock );
70
+ $ this ->productInterfaceFactoryMock = $ this ->getMockBuilder ('Magento\Catalog\Api\Data\ProductInterfaceFactory ' )
71
+ ->disableOriginalConstructor ()->getMock ();
72
+ $ this ->plugin = new BundleSaveOptions (
73
+ $ this ->productOptionRepositoryMock ,
74
+ $ this ->productInterfaceFactoryMock
75
+ );
66
76
$ this ->productExtensionMock = $ this ->getMock (
67
77
'Magento\Catalog\Api\Data\ProductExtension ' ,
68
78
['getBundleProductOptions ' ],
@@ -122,16 +132,30 @@ public function testAroundSaveWhenProductIsBundleWithOptions()
122
132
123
133
$ this ->productOptionRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ this ->productMock , $ option );
124
134
125
- $ this ->productMock ->expects ($ this ->once ( ))->method ('getSku ' )
135
+ $ this ->productMock ->expects ($ this ->exactly ( 2 ))->method ('getSku ' )
126
136
->will ($ this ->returnValue ($ productSku ));
127
137
128
138
$ this ->productOptionRepositoryMock ->expects ($ this ->once ())
129
139
->method ('getList ' )
130
140
->with ($ productSku )
131
141
->will ($ this ->returnValue ([]));
132
142
143
+ $ newProductMock = $ this ->getMockBuilder ('Magento\Catalog\Api\Data\ProductInterface ' )
144
+ ->disableOriginalConstructor ()->getMock ();
145
+ $ newProductMock ->expects ($ this ->once ())
146
+ ->method ('setSku ' )
147
+ ->with ($ productSku )
148
+ ->willReturnSelf ();
149
+ $ this ->productInterfaceFactoryMock ->expects ($ this ->once ())
150
+ ->method ('create ' )
151
+ ->willReturn ($ newProductMock );
152
+ $ this ->productRepositoryMock ->expects ($ this ->once ())
153
+ ->method ('save ' )
154
+ ->with ($ newProductMock )
155
+ ->willReturn ($ newProductMock );
156
+
133
157
$ this ->assertEquals (
134
- $ this -> productMock ,
158
+ $ newProductMock ,
135
159
$ this ->plugin ->aroundSave ($ this ->productRepositoryMock , $ this ->closureMock , $ this ->productMock )
136
160
);
137
161
}
@@ -170,7 +194,7 @@ public function testAroundSaveWhenProductIsBundleWithOptionsAndExistingOptions()
170
194
$ this ->productExtensionMock ->expects ($ this ->once ())
171
195
->method ('getBundleProductOptions ' )
172
196
->willReturn ([$ bundleOptionExisting , $ bundleOptionNew ]);
173
- $ this ->productMock ->expects ($ this ->once ( ))->method ('getSku ' )
197
+ $ this ->productMock ->expects ($ this ->exactly ( 2 ))->method ('getSku ' )
174
198
->will ($ this ->returnValue ($ productSku ));
175
199
176
200
$ this ->productOptionRepositoryMock ->expects ($ this ->once ())
@@ -193,8 +217,22 @@ public function testAroundSaveWhenProductIsBundleWithOptionsAndExistingOptions()
193
217
->method ('delete ' )
194
218
->with ($ existingOption2 );
195
219
220
+ $ newProductMock = $ this ->getMockBuilder ('Magento\Catalog\Api\Data\ProductInterface ' )
221
+ ->disableOriginalConstructor ()->getMock ();
222
+ $ newProductMock ->expects ($ this ->once ())
223
+ ->method ('setSku ' )
224
+ ->with ($ productSku )
225
+ ->willReturnSelf ();
226
+ $ this ->productInterfaceFactoryMock ->expects ($ this ->once ())
227
+ ->method ('create ' )
228
+ ->willReturn ($ newProductMock );
229
+ $ this ->productRepositoryMock ->expects ($ this ->once ())
230
+ ->method ('save ' )
231
+ ->with ($ newProductMock )
232
+ ->willReturn ($ newProductMock );
233
+
196
234
$ this ->assertEquals (
197
- $ this -> productMock ,
235
+ $ newProductMock ,
198
236
$ this ->plugin ->aroundSave ($ this ->productRepositoryMock , $ this ->closureMock , $ this ->productMock )
199
237
);
200
238
}
0 commit comments