15
15
use Magento \Setup \Fixtures \FixtureModel ;
16
16
use Magento \Store \Model \StoreManager ;
17
17
18
+ /**
19
+ * Unit test for \Magento\Setup\Fixtures\EavVariationsFixture.
20
+ */
18
21
class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
19
22
{
20
23
/**
21
- * @var \PHPUnit_Framework_MockObject_MockObject|FixtureModel
24
+ * @var FixtureModel| \PHPUnit_Framework_MockObject_MockObject
22
25
*/
23
26
private $ fixtureModelMock ;
24
27
@@ -28,22 +31,22 @@ class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
28
31
private $ model ;
29
32
30
33
/**
31
- * @var \PHPUnit_Framework_MockObject_MockObject
34
+ * @var StoreManager| \PHPUnit_Framework_MockObject_MockObject
32
35
*/
33
36
private $ storeManagerMock ;
34
37
35
38
/**
36
- * @var \PHPUnit_Framework_MockObject_MockObject
39
+ * @var Set| \PHPUnit_Framework_MockObject_MockObject
37
40
*/
38
41
private $ attributeSetMock ;
39
42
40
43
/**
41
- * @var \PHPUnit_Framework_MockObject_MockObject
44
+ * @var CacheInterface| \PHPUnit_Framework_MockObject_MockObject
42
45
*/
43
46
private $ cacheMock ;
44
47
45
48
/**
46
- * @var \PHPUnit_Framework_MockObject_MockObject
49
+ * @var Config| \PHPUnit_Framework_MockObject_MockObject
47
50
*/
48
51
private $ eavConfigMock ;
49
52
@@ -52,14 +55,24 @@ class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
52
55
*/
53
56
private $ attributeFactoryMock ;
54
57
58
+ /**
59
+ * @inheritdoc
60
+ */
55
61
public function setUp ()
56
62
{
57
- $ this ->fixtureModelMock = $ this ->getMock (FixtureModel::class, [], [], '' , false );
58
- $ this ->eavConfigMock = $ this ->getMock (Config::class, [], [], '' , false );
59
- $ this ->storeManagerMock = $ this ->getMock (StoreManager::class, [], [], '' , false );
60
- $ this ->attributeSetMock = $ this ->getMock (Set::class, [], [], '' , false );
61
- $ this ->cacheMock = $ this ->getMock (CacheInterface::class, [], [], '' , false );
62
- $ this ->attributeFactoryMock = $ this ->getMock (AttributeFactory::class, ['create ' ], [], '' , false );
63
+ $ this ->fixtureModelMock = $ this ->getMockBuilder (FixtureModel::class)
64
+ ->disableOriginalConstructor ()->getMock ();
65
+ $ this ->eavConfigMock = $ this ->getMockBuilder (Config::class)
66
+ ->disableOriginalConstructor ()->getMock ();
67
+ $ this ->storeManagerMock = $ this ->getMockBuilder (StoreManager::class)
68
+ ->disableOriginalConstructor ()->getMock ();
69
+ $ this ->attributeSetMock = $ this ->getMockBuilder (Set::class)
70
+ ->disableOriginalConstructor ()->getMock ();
71
+ $ this ->cacheMock = $ this ->getMockBuilder (CacheInterface::class)
72
+ ->disableOriginalConstructor ()->getMock ();
73
+ $ this ->attributeFactoryMock = $ this ->getMockBuilder (AttributeFactory::class)
74
+ ->setMethods (['create ' ])
75
+ ->disableOriginalConstructor ()->getMock ();
63
76
64
77
$ this ->model = (new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this ))->getObject (
65
78
EavVariationsFixture::class,
@@ -74,24 +87,32 @@ public function setUp()
74
87
);
75
88
}
76
89
77
- public function testDoNotExecuteWhenAttributeAleadyExist ()
90
+ /**
91
+ * Test for execute method when attribute already exists.
92
+ *
93
+ * @return void
94
+ */
95
+ public function testDoNotExecuteWhenAttributeAlreadyExist ()
78
96
{
79
- $ this ->fixtureModelMock
80
- ->expects ($ this ->any ())
81
- ->method ('getValue ' )
82
- ->with ('configurable_products ' , [])
83
- ->willReturn (10 );
97
+ $ this ->fixtureModelMock ->expects ($ this ->once ())
98
+ ->method ('getValue ' )->with ('configurable_products ' , [])->willReturn (10 );
84
99
$ this ->eavConfigMock ->expects ($ this ->once ())->method ('getEntityAttributeCodes ' )
85
100
->willReturn (['configurable_variation ' ]);
86
101
$ this ->attributeFactoryMock ->expects ($ this ->never ())->method ('create ' );
87
102
88
103
$ this ->model ->execute ();
89
104
}
90
105
106
+ /**
107
+ * Test for execute method.
108
+ *
109
+ * @return void
110
+ */
91
111
public function testExecute ()
92
112
{
93
- $ this ->eavConfigMock ->expects ($ this ->once ())->method ('getEntityAttributeCodes ' )
94
- ->willReturn (['attr1 ' , 'attr2 ' ]);
113
+ $ storeId = 5 ;
114
+ $ this ->eavConfigMock ->expects ($ this ->once ())
115
+ ->method ('getEntityAttributeCodes ' )->willReturn (['attr1 ' , 'attr2 ' ]);
95
116
$ this ->fixtureModelMock
96
117
->expects ($ this ->any ())
97
118
->method ('getValue ' )
@@ -100,42 +121,33 @@ public function testExecute()
100
121
['configurable_products_variation ' , 3 , 1 ],
101
122
]);
102
123
103
- $ storeMock = $ this ->getMock (\Magento \Store \Model \Store::class, [], [], '' , false );
104
- $ this ->storeManagerMock ->expects ($ this ->once ())
105
- ->method ('getStores ' )
106
- ->will ($ this ->returnValue ([$ storeMock ]));
107
-
124
+ $ storeMock = $ this ->getMockBuilder (\Magento \Store \Model \Store::class)
125
+ ->disableOriginalConstructor ()->getMock ();
126
+ $ this ->storeManagerMock ->expects ($ this ->once ())->method ('getStores ' )->willReturn ([$ storeId => $ storeMock ]);
108
127
$ this ->attributeSetMock ->expects ($ this ->once ())->method ('load ' )->willReturnSelf ();
109
- $ this ->attributeSetMock ->expects ($ this ->once ())
110
- ->method ('getDefaultGroupId ' )
111
- ->will ($ this ->returnValue (2 ));
128
+ $ this ->attributeSetMock ->expects ($ this ->once ())->method ('getDefaultGroupId ' )->willReturn (2 );
112
129
113
130
$ attributeMock = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class)
114
131
->setMethods ([
115
132
'setAttributeSetId ' ,
116
133
'setAttributeGroupId ' ,
117
134
'save ' ,
118
- ])->disableOriginalConstructor ()
119
- ->getMock ();
120
- $ attributeMock ->expects ($ this ->exactly (2 ))
121
- ->method ('setAttributeSetId ' )
122
- ->willReturnSelf ();
123
- $ attributeMock ->expects ($ this ->once ())
124
- ->method ('setAttributeGroupId ' )
125
- ->willReturnSelf ();
135
+ ])
136
+ ->disableOriginalConstructor ()->getMock ();
137
+ $ attributeMock ->expects ($ this ->exactly (2 ))->method ('setAttributeSetId ' )->willReturnSelf ();
138
+ $ attributeMock ->expects ($ this ->once ())->method ('setAttributeGroupId ' )->willReturnSelf ();
126
139
$ this ->attributeFactoryMock ->expects ($ this ->once ())->method ('create ' )
127
140
->with (
128
141
[
129
142
'data ' => [
130
143
'frontend_label ' => [
131
- 'configurable variations ' ,
132
- 'configurable variations ' ,
144
+ $ storeId => 'configurable variations ' ,
133
145
],
134
146
'frontend_input ' => 'select ' ,
135
147
'is_required ' => '0 ' ,
136
148
'option ' => [
137
149
'order ' => ['option_1 ' => 1 ],
138
- 'value ' => ['option_1 ' => [' option 1 ' , 'option 1 ' ]],
150
+ 'value ' => ['option_1 ' => [$ storeId => 'option 1 ' ]],
139
151
'delete ' => ['option_1 ' => '' ],
140
152
],
141
153
'default ' => ['option_0 ' ],
@@ -172,16 +184,27 @@ public function testExecute()
172
184
]
173
185
]
174
186
)->willReturn ($ attributeMock );
175
- $ this ->cacheMock ->expects ($ this ->once ())->method ('remove ' )->with (Config::ATTRIBUTES_CACHE_ID . Product::ENTITY );
187
+ $ this ->cacheMock ->expects ($ this ->once ())
188
+ ->method ('remove ' )->with (Config::ATTRIBUTES_CACHE_ID . Product::ENTITY );
176
189
177
190
$ this ->model ->execute ();
178
191
}
179
192
193
+ /**
194
+ * Test for getActionTitle method.
195
+ *
196
+ * @return void
197
+ */
180
198
public function testGetActionTitle ()
181
199
{
182
200
$ this ->assertSame ('Generating configurable EAV variations ' , $ this ->model ->getActionTitle ());
183
201
}
184
202
203
+ /**
204
+ * Test for introduceParamLabels method.
205
+ *
206
+ * @return void
207
+ */
185
208
public function testIntroduceParamLabels ()
186
209
{
187
210
$ this ->assertSame ([], $ this ->model ->introduceParamLabels ());
0 commit comments