11
11
use Magento \Eav \Setup \EavSetup ;
12
12
use Magento \Eav \Setup \EavSetupFactory ;
13
13
use Magento \Framework \DB \Adapter \AdapterInterface ;
14
- use Magento \Framework \DB \Query \BatchIteratorInterface ;
15
- use Magento \Framework \DB \Query \Generator ;
16
14
use Magento \Framework \DB \Select ;
17
15
use Magento \Framework \Setup \ModuleDataSetupInterface ;
18
- use PHPUnit \Framework \MockObject \MockObject ;
19
16
use PHPUnit \Framework \TestCase ;
20
17
21
18
class UpdateMultiselectAttributesBackendTypesTest extends TestCase
22
19
{
23
20
/**
24
- * @var ModuleDataSetupInterface|MockObject
21
+ * @var ModuleDataSetupInterface|\PHPUnit\Framework\MockObject\ MockObject
25
22
*/
26
23
private $ dataSetup ;
27
24
28
25
/**
29
- * @var EavSetupFactory|MockObject
26
+ * @var EavSetupFactory|\PHPUnit\Framework\MockObject\ MockObject
30
27
*/
31
28
private $ eavSetupFactory ;
32
29
33
- /**
34
- * @var Generator|MockObject
35
- */
36
- private $ batchQueryGenerator ;
37
-
38
30
/**
39
31
* @var UpdateMultiselectAttributesBackendTypes
40
32
*/
@@ -48,64 +40,37 @@ protected function setUp(): void
48
40
parent ::setUp ();
49
41
$ this ->dataSetup = $ this ->createMock (ModuleDataSetupInterface::class);
50
42
$ 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 );
57
44
}
58
45
59
- /**
60
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
61
- * @return void
62
- */
63
46
public function testApply (): void
64
47
{
65
48
$ attributeIds = [3 , 7 ];
66
49
$ entityTypeId = 4 ;
67
50
$ eavSetup = $ this ->createMock (EavSetup::class);
68
51
$ 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 ' )
82
58
->willReturn ($ eavSetup );
83
- $ this ->dataSetup ->expects ($ this ->once ())
84
- ->method ('getConnection ' )
59
+ $ this ->dataSetup ->method ('getConnection ' )
85
60
->willReturn ($ connection );
86
61
$ this ->dataSetup ->method ('getTable ' )
87
62
->willReturnArgument (0 );
88
- $ this ->batchQueryGenerator ->expects ($ this ->once ())
89
- ->method ('generate ' )
90
- ->willReturn ($ batchIterator );
91
63
$ eavSetup ->method ('getEntityTypeId ' )
92
64
->willReturn (4 );
93
- $ eavSetup ->expects ($ this ->exactly (2 ))
94
- ->method ('updateAttribute ' )
65
+ $ eavSetup ->method ('updateAttribute ' )
95
66
->withConsecutive (
96
67
[$ entityTypeId , 3 , 'backend_type ' , 'text ' ],
97
68
[$ entityTypeId , 7 , 'backend_type ' , 'text ' ]
98
69
);
99
- $ connection ->expects ($ this ->exactly (4 ))
70
+ $ connection ->expects ($ this ->exactly (2 ))
100
71
->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 ' )
109
74
->willReturn (
110
75
[
111
76
'value_id ' => [],
@@ -115,78 +80,39 @@ public function testApply(): void
115
80
'row_id ' => [],
116
81
]
117
82
);
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 )
121
89
->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 ' ])
128
92
->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 ' )
135
95
->willReturn ('' );
136
- $ selectAttributes ->expects ($ this ->once ())
137
- ->method ('from ' )
96
+ $ select1 ->method ('from ' )
138
97
->with ('eav_attribute ' , ['attribute_id ' ])
139
98
->willReturnSelf ();
140
- $ selectAttributes ->expects ($ this ->exactly (3 ))
141
- ->method ('where ' )
99
+ $ select1 ->method ('where ' )
142
100
->withConsecutive (
143
101
['entity_type_id = ? ' , $ entityTypeId ],
144
102
['backend_type = ? ' , 'varchar ' ],
145
103
['frontend_input = ? ' , 'multiselect ' ]
146
104
)
147
105
->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 ' )
162
108
->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 )
180
111
->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 ' ])
187
114
->willReturnSelf ();
188
- $ selectAttributesValues ->expects ($ this ->once ())
189
- ->method ('where ' )
115
+ $ select3 ->method ('where ' )
190
116
->with ('attribute_id in (?) ' , $ attributeIds )
191
117
->willReturnSelf ();
192
118
$ this ->model ->apply ();
0 commit comments