Skip to content

Commit 0fdc3f7

Browse files
JosephMaxwellmageprince
authored andcommitted
Adding test coverage for Group Repository not copying extension attributes.
1 parent 6178786 commit 0fdc3f7

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/GroupRepositoryTest.php

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class GroupRepositoryTest extends \PHPUnit\Framework\TestCase
3737
* @var \Magento\Customer\Api\Data\GroupInterface|\PHPUnit_Framework_MockObject_MockObject
3838
*/
3939
protected $group;
40+
41+
/**
42+
* @var \Magento\Customer\Api\Data\GroupInterface|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
protected $factoryCreatedGroup;
4045

4146
/**
4247
* @var \Magento\Customer\Model\ResourceModel\Group|\PHPUnit_Framework_MockObject_MockObject
@@ -153,6 +158,12 @@ private function setupGroupObjects()
153158
'group',
154159
false
155160
);
161+
$this->factoryCreatedGroup = $this->getMockForAbstractClass(
162+
\Magento\Customer\Api\Data\GroupInterface::class,
163+
[],
164+
'group',
165+
false
166+
);
156167

157168
$this->groupResourceModel = $this->createMock(\Magento\Customer\Model\ResourceModel\Group::class);
158169
}
@@ -162,16 +173,20 @@ public function testSave()
162173
$groupId = 0;
163174

164175
$taxClass = $this->getMockForAbstractClass(\Magento\Tax\Api\Data\TaxClassInterface::class, [], '', false);
176+
$groupExtensionAttributes = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\GroupExtensionInterface::class);
165177

166-
$this->group->expects($this->once())
178+
$this->group->expects($this->atLeastOnce())
167179
->method('getCode')
168180
->willReturn('Code');
169181
$this->group->expects($this->atLeastOnce())
170182
->method('getId')
171183
->willReturn($groupId);
172-
$this->group->expects($this->once())
184+
$this->group->expects($this->atLeastOnce())
173185
->method('getTaxClassId')
174186
->willReturn(17);
187+
$this->group->expects($this->atLeastOnce())
188+
->method('getExtensionAttributes')
189+
->willReturn($groupExtensionAttributes);
175190

176191
$this->groupModel->expects($this->atLeastOnce())
177192
->method('getId')
@@ -185,22 +200,34 @@ public function testSave()
185200
$this->groupModel->expects($this->atLeastOnce())
186201
->method('getTaxClassName')
187202
->willReturn('Tax class name');
188-
$this->group->expects($this->once())
203+
204+
205+
$this->factoryCreatedGroup->expects($this->once())
189206
->method('setId')
190207
->with($groupId)
191208
->willReturnSelf();
192-
$this->group->expects($this->once())
209+
$this->factoryCreatedGroup->expects($this->once())
193210
->method('setCode')
194211
->with('Code')
195212
->willReturnSelf();
196-
$this->group->expects($this->once())
213+
$this->factoryCreatedGroup->expects($this->once())
197214
->method('setTaxClassId')
198215
->with(234)
199216
->willReturnSelf();
200-
$this->group->expects($this->once())
217+
$this->factoryCreatedGroup->expects($this->once())
201218
->method('setTaxClassName')
202219
->with('Tax class name')
203220
->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);
204231

205232
$this->taxClassRepository->expects($this->once())
206233
->method('get')
@@ -229,9 +256,12 @@ public function testSave()
229256
->with($groupId);
230257
$this->groupDataFactory->expects($this->once())
231258
->method('create')
232-
->willReturn($this->group);
259+
->willReturn($this->factoryCreatedGroup);
260+
261+
$updatedGroup = $this->model->save($this->group);
233262

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());
235265
}
236266

237267
/**

0 commit comments

Comments
 (0)