1515use Magento \Setup \Fixtures \FixtureModel ;
1616use Magento \Store \Model \StoreManager ;
1717
18+ /**
19+ * Unit test for \Magento\Setup\Fixtures\EavVariationsFixture.
20+ */
1821class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
1922{
2023 /**
21- * @var \PHPUnit_Framework_MockObject_MockObject|FixtureModel
24+ * @var FixtureModel| \PHPUnit_Framework_MockObject_MockObject
2225 */
2326 private $ fixtureModelMock ;
2427
@@ -28,22 +31,22 @@ class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
2831 private $ model ;
2932
3033 /**
31- * @var \PHPUnit_Framework_MockObject_MockObject
34+ * @var StoreManager| \PHPUnit_Framework_MockObject_MockObject
3235 */
3336 private $ storeManagerMock ;
3437
3538 /**
36- * @var \PHPUnit_Framework_MockObject_MockObject
39+ * @var Set| \PHPUnit_Framework_MockObject_MockObject
3740 */
3841 private $ attributeSetMock ;
3942
4043 /**
41- * @var \PHPUnit_Framework_MockObject_MockObject
44+ * @var CacheInterface| \PHPUnit_Framework_MockObject_MockObject
4245 */
4346 private $ cacheMock ;
4447
4548 /**
46- * @var \PHPUnit_Framework_MockObject_MockObject
49+ * @var Config| \PHPUnit_Framework_MockObject_MockObject
4750 */
4851 private $ eavConfigMock ;
4952
@@ -52,14 +55,24 @@ class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
5255 */
5356 private $ attributeFactoryMock ;
5457
58+ /**
59+ * @inheritdoc
60+ */
5561 public function setUp ()
5662 {
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 ();
6376
6477 $ this ->model = (new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this ))->getObject (
6578 EavVariationsFixture::class,
@@ -74,24 +87,32 @@ public function setUp()
7487 );
7588 }
7689
77- public function testDoNotExecuteWhenAttributeAleadyExist ()
90+ /**
91+ * Test for execute method when attribute already exists.
92+ *
93+ * @return void
94+ */
95+ public function testDoNotExecuteWhenAttributeAlreadyExist ()
7896 {
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 );
8499 $ this ->eavConfigMock ->expects ($ this ->once ())->method ('getEntityAttributeCodes ' )
85100 ->willReturn (['configurable_variation ' ]);
86101 $ this ->attributeFactoryMock ->expects ($ this ->never ())->method ('create ' );
87102
88103 $ this ->model ->execute ();
89104 }
90105
106+ /**
107+ * Test for execute method.
108+ *
109+ * @return void
110+ */
91111 public function testExecute ()
92112 {
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 ' ]);
95116 $ this ->fixtureModelMock
96117 ->expects ($ this ->any ())
97118 ->method ('getValue ' )
@@ -100,42 +121,33 @@ public function testExecute()
100121 ['configurable_products_variation ' , 3 , 1 ],
101122 ]);
102123
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 ]);
108127 $ 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 );
112129
113130 $ attributeMock = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class)
114131 ->setMethods ([
115132 'setAttributeSetId ' ,
116133 'setAttributeGroupId ' ,
117134 '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 ();
126139 $ this ->attributeFactoryMock ->expects ($ this ->once ())->method ('create ' )
127140 ->with (
128141 [
129142 'data ' => [
130143 'frontend_label ' => [
131- 'configurable variations ' ,
132- 'configurable variations ' ,
144+ $ storeId => 'configurable variations ' ,
133145 ],
134146 'frontend_input ' => 'select ' ,
135147 'is_required ' => '0 ' ,
136148 'option ' => [
137149 'order ' => ['option_1 ' => 1 ],
138- 'value ' => ['option_1 ' => [' option 1 ' , 'option 1 ' ]],
150+ 'value ' => ['option_1 ' => [$ storeId => 'option 1 ' ]],
139151 'delete ' => ['option_1 ' => '' ],
140152 ],
141153 'default ' => ['option_0 ' ],
@@ -172,16 +184,27 @@ public function testExecute()
172184 ]
173185 ]
174186 )->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 );
176189
177190 $ this ->model ->execute ();
178191 }
179192
193+ /**
194+ * Test for getActionTitle method.
195+ *
196+ * @return void
197+ */
180198 public function testGetActionTitle ()
181199 {
182200 $ this ->assertSame ('Generating configurable EAV variations ' , $ this ->model ->getActionTitle ());
183201 }
184202
203+ /**
204+ * Test for introduceParamLabels method.
205+ *
206+ * @return void
207+ */
185208 public function testIntroduceParamLabels ()
186209 {
187210 $ this ->assertSame ([], $ this ->model ->introduceParamLabels ());
0 commit comments