@@ -37,6 +37,11 @@ class GroupRepositoryTest extends \PHPUnit\Framework\TestCase
37
37
* @var \Magento\Customer\Api\Data\GroupInterface|\PHPUnit_Framework_MockObject_MockObject
38
38
*/
39
39
protected $ group ;
40
+
41
+ /**
42
+ * @var \Magento\Customer\Api\Data\GroupInterface|\PHPUnit_Framework_MockObject_MockObject
43
+ */
44
+ protected $ factoryCreatedGroup ;
40
45
41
46
/**
42
47
* @var \Magento\Customer\Model\ResourceModel\Group|\PHPUnit_Framework_MockObject_MockObject
@@ -153,6 +158,12 @@ private function setupGroupObjects()
153
158
'group ' ,
154
159
false
155
160
);
161
+ $ this ->factoryCreatedGroup = $ this ->getMockForAbstractClass (
162
+ \Magento \Customer \Api \Data \GroupInterface::class,
163
+ [],
164
+ 'group ' ,
165
+ false
166
+ );
156
167
157
168
$ this ->groupResourceModel = $ this ->createMock (\Magento \Customer \Model \ResourceModel \Group::class);
158
169
}
@@ -162,16 +173,20 @@ public function testSave()
162
173
$ groupId = 0 ;
163
174
164
175
$ taxClass = $ this ->getMockForAbstractClass (\Magento \Tax \Api \Data \TaxClassInterface::class, [], '' , false );
176
+ $ groupExtensionAttributes = $ this ->getMockForAbstractClass (\Magento \Customer \Api \Data \GroupExtensionInterface::class);
165
177
166
- $ this ->group ->expects ($ this ->once ())
178
+ $ this ->group ->expects ($ this ->atLeastOnce ())
167
179
->method ('getCode ' )
168
180
->willReturn ('Code ' );
169
181
$ this ->group ->expects ($ this ->atLeastOnce ())
170
182
->method ('getId ' )
171
183
->willReturn ($ groupId );
172
- $ this ->group ->expects ($ this ->once ())
184
+ $ this ->group ->expects ($ this ->atLeastOnce ())
173
185
->method ('getTaxClassId ' )
174
186
->willReturn (17 );
187
+ $ this ->group ->expects ($ this ->atLeastOnce ())
188
+ ->method ('getExtensionAttributes ' )
189
+ ->willReturn ($ groupExtensionAttributes );
175
190
176
191
$ this ->groupModel ->expects ($ this ->atLeastOnce ())
177
192
->method ('getId ' )
@@ -185,22 +200,34 @@ public function testSave()
185
200
$ this ->groupModel ->expects ($ this ->atLeastOnce ())
186
201
->method ('getTaxClassName ' )
187
202
->willReturn ('Tax class name ' );
188
- $ this ->group ->expects ($ this ->once ())
203
+
204
+
205
+ $ this ->factoryCreatedGroup ->expects ($ this ->once ())
189
206
->method ('setId ' )
190
207
->with ($ groupId )
191
208
->willReturnSelf ();
192
- $ this ->group ->expects ($ this ->once ())
209
+ $ this ->factoryCreatedGroup ->expects ($ this ->once ())
193
210
->method ('setCode ' )
194
211
->with ('Code ' )
195
212
->willReturnSelf ();
196
- $ this ->group ->expects ($ this ->once ())
213
+ $ this ->factoryCreatedGroup ->expects ($ this ->once ())
197
214
->method ('setTaxClassId ' )
198
215
->with (234 )
199
216
->willReturnSelf ();
200
- $ this ->group ->expects ($ this ->once ())
217
+ $ this ->factoryCreatedGroup ->expects ($ this ->once ())
201
218
->method ('setTaxClassName ' )
202
219
->with ('Tax class name ' )
203
220
->willReturnSelf ();
221
+ $ this ->factoryCreatedGroup ->expects ($ this ->once ())
222
+ ->method ('setExtensionAttributes ' )
223
+ ->with ($ groupExtensionAttributes )
224
+ ->willReturnSelf ();
225
+ $ this ->factoryCreatedGroup ->expects ($ this ->atLeastOnce ())
226
+ ->method ('getCode ' )
227
+ ->willReturn ('Code ' );
228
+ $ this ->factoryCreatedGroup ->expects ($ this ->atLeastOnce ())
229
+ ->method ('getTaxClassId ' )
230
+ ->willReturn (17 );
204
231
205
232
$ this ->taxClassRepository ->expects ($ this ->once ())
206
233
->method ('get ' )
@@ -229,9 +256,12 @@ public function testSave()
229
256
->with ($ groupId );
230
257
$ this ->groupDataFactory ->expects ($ this ->once ())
231
258
->method ('create ' )
232
- ->willReturn ($ this ->group );
259
+ ->willReturn ($ this ->factoryCreatedGroup );
260
+
261
+ $ updatedGroup = $ this ->model ->save ($ this ->group );
233
262
234
- $ this ->assertSame ($ this ->group , $ this ->model ->save ($ this ->group ));
263
+ $ this ->assertSame ($ this ->group ->getCode (), $ updatedGroup ->getCode ());
264
+ $ this ->assertSame ($ this ->group ->getTaxClassId (), $ updatedGroup ->getTaxClassId ());
235
265
}
236
266
237
267
/**
0 commit comments