Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerGroupsFixtureTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Customer\Api\Data\GroupInterfaceFactory;
12 use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
14 
18 class CustomerGroupsFixtureTest extends \PHPUnit\Framework\TestCase
19 {
23  private $fixtureModelMock;
24 
28  private $groupCollectionFactoryMock;
29 
33  private $groupRepositoryMock;
34 
38  private $groupFactoryMock;
39 
43  private $groupDataObjectMock;
44 
48  private $model;
49 
50  public function testExecute()
51  {
52  $this->fixtureModelMock = $this->getMockBuilder(\Magento\Setup\Fixtures\FixtureModel::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55 
56  //Mock repository for customer groups
57  $this->groupRepositoryMock = $this->getMockBuilder(GroupRepositoryInterface::class)
58  ->disableOriginalConstructor()
59  ->getMock();
60 
61  //Mock for customer groups collection
62  $this->groupCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
63  ->setMethods(['create', 'getSize'])
64  ->disableOriginalConstructor()
65  ->getMock();
66 
67  $this->groupCollectionFactoryMock
68  ->expects($this->once())
69  ->method('create')
70  ->willReturn($this->groupCollectionFactoryMock);
71 
72  $this->groupCollectionFactoryMock
73  ->expects($this->once())
74  ->method('getSize')
75  ->willReturn(0);
76 
77  //Mock customer groups data object
78  $this->groupDataObjectMock = $this->getMockBuilder(GroupInterface::class)
79  ->setMethods(['setCode', 'setTaxClassId', 'save'])
80  ->disableOriginalConstructor()
81  ->getMockForAbstractClass();
82 
83  //Mock customer groups factory
84  $this->groupFactoryMock = $this->getMockBuilder(GroupInterfaceFactory::class)
85  ->setMethods(['create'])
86  ->disableOriginalConstructor()
87  ->getMock();
88 
89  $this->groupFactoryMock
90  ->expects($this->once())
91  ->method('create')
92  ->willReturn($this->groupDataObjectMock);
93 
94  $this->groupDataObjectMock
95  ->expects($this->once())
96  ->method('setCode')
97  ->willReturn($this->groupDataObjectMock);
98 
99  $this->groupDataObjectMock
100  ->expects($this->once())
101  ->method('setTaxClassId')
102  ->willReturn($this->groupDataObjectMock);
103 
104  $this->groupRepositoryMock
105  ->expects($this->once())
106  ->method('save')
107  ->willReturn($this->groupDataObjectMock);
108 
109  $this->fixtureModelMock
110  ->expects($this->once())
111  ->method('getValue')
112  ->will($this->returnValue(1));
113 
114  $this->model = new CustomerGroupsFixture(
115  $this->fixtureModelMock,
116  $this->groupCollectionFactoryMock,
117  $this->groupRepositoryMock,
118  $this->groupFactoryMock
119  );
120 
121  $this->model->execute();
122  }
123 }