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