1111use Magento \Eav \Setup \EavSetup ;
1212use Magento \Eav \Setup \EavSetupFactory ;
1313use Magento \Framework \DB \Adapter \AdapterInterface ;
14- use Magento \Framework \DB \Query \BatchIteratorInterface ;
15- use Magento \Framework \DB \Query \Generator ;
1614use Magento \Framework \DB \Select ;
1715use Magento \Framework \Setup \ModuleDataSetupInterface ;
18- use PHPUnit \Framework \MockObject \MockObject ;
1916use PHPUnit \Framework \TestCase ;
2017
2118class UpdateMultiselectAttributesBackendTypesTest extends TestCase
2219{
2320 /**
24- * @var ModuleDataSetupInterface|MockObject
21+ * @var ModuleDataSetupInterface|\PHPUnit\Framework\MockObject\ MockObject
2522 */
2623 private $ dataSetup ;
2724
2825 /**
29- * @var EavSetupFactory|MockObject
26+ * @var EavSetupFactory|\PHPUnit\Framework\MockObject\ MockObject
3027 */
3128 private $ eavSetupFactory ;
3229
33- /**
34- * @var Generator|MockObject
35- */
36- private $ batchQueryGenerator ;
37-
3830 /**
3931 * @var UpdateMultiselectAttributesBackendTypes
4032 */
@@ -48,64 +40,37 @@ protected function setUp(): void
4840 parent ::setUp ();
4941 $ this ->dataSetup = $ this ->createMock (ModuleDataSetupInterface::class);
5042 $ this ->eavSetupFactory = $ this ->createMock (EavSetupFactory::class);
51- $ this ->batchQueryGenerator = $ this ->createMock (Generator::class);
52- $ this ->model = new UpdateMultiselectAttributesBackendTypes (
53- $ this ->dataSetup ,
54- $ this ->eavSetupFactory ,
55- $ this ->batchQueryGenerator
56- );
43+ $ this ->model = new UpdateMultiselectAttributesBackendTypes ($ this ->dataSetup , $ this ->eavSetupFactory );
5744 }
5845
59- /**
60- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
61- * @return void
62- */
6346 public function testApply (): void
6447 {
6548 $ attributeIds = [3 , 7 ];
6649 $ entityTypeId = 4 ;
6750 $ eavSetup = $ this ->createMock (EavSetup::class);
6851 $ connection = $ this ->createMock (AdapterInterface::class);
69- $ selectAttributes = $ this ->createMock (Select::class);
70- $ selectAttributesValues = $ this ->createMock (Select::class);
71- $ selectForInsert1 = $ this ->createMock (Select::class);
72- $ selectForInsert2 = $ this ->createMock (Select::class);
73- $ selectForDelete1 = $ this ->createMock (Select::class);
74- $ selectForDelete2 = $ this ->createMock (Select::class);
75- $ batchIterator = $ this ->getMockForAbstractClass (BatchIteratorInterface::class);
76- $ batchIterator ->method ('current ' )
77- ->willReturnOnConsecutiveCalls ($ selectForInsert1 , $ selectForInsert2 );
78- $ batchIterator ->method ('valid ' )
79- ->willReturnOnConsecutiveCalls (true , true , false );
80- $ this ->eavSetupFactory ->expects ($ this ->once ())
81- ->method ('create ' )
52+ $ select1 = $ this ->createMock (Select::class);
53+ $ select2 = $ this ->createMock (Select::class);
54+ $ select3 = $ this ->createMock (Select::class);
55+ $ statement = $ this ->createMock (\Zend_Db_Statement_Interface::class);
56+
57+ $ this ->eavSetupFactory ->method ('create ' )
8258 ->willReturn ($ eavSetup );
83- $ this ->dataSetup ->expects ($ this ->once ())
84- ->method ('getConnection ' )
59+ $ this ->dataSetup ->method ('getConnection ' )
8560 ->willReturn ($ connection );
8661 $ this ->dataSetup ->method ('getTable ' )
8762 ->willReturnArgument (0 );
88- $ this ->batchQueryGenerator ->expects ($ this ->once ())
89- ->method ('generate ' )
90- ->willReturn ($ batchIterator );
9163 $ eavSetup ->method ('getEntityTypeId ' )
9264 ->willReturn (4 );
93- $ eavSetup ->expects ($ this ->exactly (2 ))
94- ->method ('updateAttribute ' )
65+ $ eavSetup ->method ('updateAttribute ' )
9566 ->withConsecutive (
9667 [$ entityTypeId , 3 , 'backend_type ' , 'text ' ],
9768 [$ entityTypeId , 7 , 'backend_type ' , 'text ' ]
9869 );
99- $ connection ->expects ($ this ->exactly (4 ))
70+ $ connection ->expects ($ this ->exactly (2 ))
10071 ->method ('select ' )
101- ->willReturnOnConsecutiveCalls (
102- $ selectAttributes ,
103- $ selectAttributesValues ,
104- $ selectForDelete1 ,
105- $ selectForDelete2
106- );
107- $ connection ->expects ($ this ->once ())
108- ->method ('describeTable ' )
72+ ->willReturnOnConsecutiveCalls ($ select1 , $ select2 , $ select3 );
73+ $ connection ->method ('describeTable ' )
10974 ->willReturn (
11075 [
11176 'value_id ' => [],
@@ -115,78 +80,39 @@ public function testApply(): void
11580 'row_id ' => [],
11681 ]
11782 );
118- $ connection ->expects ($ this ->once ())
119- ->method ('fetchCol ' )
120- ->with ($ selectAttributes )
83+ $ connection ->method ('query ' )
84+ ->willReturn ($ statement );
85+ $ connection ->method ('fetchAll ' )
86+ ->willReturn ([]);
87+ $ connection ->method ('fetchCol ' )
88+ ->with ($ select1 )
12189 ->willReturn ($ attributeIds );
122- $ connection ->expects ($ this ->exactly (2 ))
123- ->method ('insertFromSelect ' )
124- ->withConsecutive (
125- [$ selectForInsert1 , 'catalog_product_entity_text ' , ['attribute_id ' , 'store_id ' , 'value ' , 'row_id ' ]],
126- [$ selectForInsert2 , 'catalog_product_entity_text ' , ['attribute_id ' , 'store_id ' , 'value ' , 'row_id ' ]],
127- )
90+ $ connection ->method ('insertFromSelect ' )
91+ ->with ($ select3 , 'catalog_product_entity_text ' , ['attribute_id ' , 'store_id ' , 'value ' , 'row_id ' ])
12892 ->willReturn ('' );
129- $ connection ->expects ($ this ->exactly (2 ))
130- ->method ('delete ' )
131- ->withConsecutive (
132- ['catalog_product_entity_varchar ' , 'value_id IN (select1) ' ],
133- ['catalog_product_entity_varchar ' , 'value_id IN (select2) ' ],
134- )
93+ $ connection ->method ('deleteFromSelect ' )
94+ ->with ($ select2 , 'catalog_product_entity_varchar ' )
13595 ->willReturn ('' );
136- $ selectAttributes ->expects ($ this ->once ())
137- ->method ('from ' )
96+ $ select1 ->method ('from ' )
13897 ->with ('eav_attribute ' , ['attribute_id ' ])
13998 ->willReturnSelf ();
140- $ selectAttributes ->expects ($ this ->exactly (3 ))
141- ->method ('where ' )
99+ $ select1 ->method ('where ' )
142100 ->withConsecutive (
143101 ['entity_type_id = ? ' , $ entityTypeId ],
144102 ['backend_type = ? ' , 'varchar ' ],
145103 ['frontend_input = ? ' , 'multiselect ' ]
146104 )
147105 ->willReturnSelf ();
148- $ selectForInsert1 ->expects ($ this ->exactly (2 ))
149- ->method ('reset ' )
150- ->with (Select::COLUMNS )
151- ->willReturnSelf ();
152- $ selectForInsert1 ->expects ($ this ->exactly (2 ))
153- ->method ('columns ' )
154- ->withConsecutive (
155- [['attribute_id ' , 'store_id ' , 'value ' , 'row_id ' ]],
156- ['value_id ' ]
157- )
158- ->willReturnSelf ();
159- $ selectForInsert2 ->expects ($ this ->exactly (2 ))
160- ->method ('reset ' )
161- ->with (Select::COLUMNS )
106+ $ select2 ->method ('from ' )
107+ ->with ('catalog_product_entity_varchar ' )
162108 ->willReturnSelf ();
163- $ selectForInsert2 ->expects ($ this ->exactly (2 ))
164- ->method ('columns ' )
165- ->withConsecutive (
166- [['attribute_id ' , 'store_id ' , 'value ' , 'row_id ' ]],
167- ['value_id ' ]
168- )
169- ->willReturnSelf ();
170- $ selectForDelete1 ->expects ($ this ->once ())
171- ->method ('from ' )
172- ->with ($ selectForInsert1 , 'value_id ' )
173- ->willReturnSelf ();
174- $ selectForDelete1 ->expects ($ this ->once ())
175- ->method ('assemble ' )
176- ->willReturn ('select1 ' );
177- $ selectForDelete2 ->expects ($ this ->once ())
178- ->method ('from ' )
179- ->with ($ selectForInsert2 , 'value_id ' )
109+ $ select2 ->method ('where ' )
110+ ->with ('attribute_id in (?) ' , $ attributeIds )
180111 ->willReturnSelf ();
181- $ selectForDelete2 ->expects ($ this ->once ())
182- ->method ('assemble ' )
183- ->willReturn ('select2 ' );
184- $ selectAttributesValues ->expects ($ this ->once ())
185- ->method ('from ' )
186- ->with ('catalog_product_entity_varchar ' , '* ' )
112+ $ select3 ->method ('from ' )
113+ ->with ('catalog_product_entity_varchar ' , ['attribute_id ' , 'store_id ' , 'value ' , 'row_id ' ])
187114 ->willReturnSelf ();
188- $ selectAttributesValues ->expects ($ this ->once ())
189- ->method ('where ' )
115+ $ select3 ->method ('where ' )
190116 ->with ('attribute_id in (?) ' , $ attributeIds )
191117 ->willReturnSelf ();
192118 $ this ->model ->apply ();
0 commit comments