6
6
*/
7
7
namespace Magento \CatalogImportExport \Test \Unit \Model \Import \Product \Type ;
8
8
9
+ use Magento \Catalog \Model \ResourceModel \Product \Attribute \CollectionFactory as AttributeCollectionFactory ;
9
10
use Magento \CatalogImportExport \Model \Import \Product ;
10
11
use Magento \CatalogImportExport \Model \Import \Product \RowValidatorInterface ;
11
12
use Magento \CatalogImportExport \Model \Import \Product \Type \AbstractType as AbstractType ;
12
13
use Magento \CatalogImportExport \Model \Import \Product \Type \Simple ;
13
14
use Magento \Eav \Model \Entity \Attribute ;
14
15
use Magento \Eav \Model \Entity \Attribute \Set ;
15
16
use Magento \Eav \Model \ResourceModel \Entity \Attribute \Set \Collection ;
17
+ use Magento \Eav \Model \ResourceModel \Entity \Attribute \Set \CollectionFactory as AttributeSetCollectionFactory ;
16
18
use Magento \Framework \App \ResourceConnection ;
17
19
use Magento \Framework \DB \Adapter \AdapterInterface ;
18
20
use Magento \Framework \DB \Adapter \Pdo \Mysql ;
@@ -68,12 +70,12 @@ protected function setUp(): void
68
70
{
69
71
$ this ->entityModel = $ this ->createMock (Product::class);
70
72
$ attrSetColFactory = $ this ->createPartialMock (
71
- \ Magento \ Eav \ Model \ ResourceModel \ Entity \ Attribute \ Set \CollectionFactory ::class,
73
+ AttributeSetCollectionFactory ::class,
72
74
['create ' ]
73
75
);
74
76
$ attrSetCollection = $ this ->createMock (Collection::class);
75
77
$ attrColFactory = $ this ->createPartialMock (
76
- \ Magento \ Catalog \ Model \ ResourceModel \ Product \ Attribute \CollectionFactory ::class,
78
+ AttributeCollectionFactory ::class,
77
79
['create ' ]
78
80
);
79
81
$ attributeSet = $ this ->createMock (Set::class);
@@ -100,14 +102,22 @@ protected function setUp(): void
100
102
)
101
103
->disableOriginalConstructor ()
102
104
->getMock ();
103
- $ attribute ->expects ($ this ->any ())->method ('getIsVisible ' )->willReturn (true );
104
- $ attribute ->expects ($ this ->any ())->method ('getIsGlobal ' )->willReturn (true );
105
- $ attribute ->expects ($ this ->any ())->method ('getIsRequired ' )->willReturn (true );
106
- $ attribute ->expects ($ this ->any ())->method ('getIsUnique ' )->willReturn (true );
107
- $ attribute ->expects ($ this ->any ())->method ('getFrontendLabel ' )->willReturn ('frontend_label ' );
108
- $ attribute ->expects ($ this ->any ())->method ('getApplyTo ' )->willReturn (['simple ' ]);
109
- $ attribute ->expects ($ this ->any ())->method ('getDefaultValue ' )->willReturn ('default_value ' );
110
- $ attribute ->expects ($ this ->any ())->method ('usesSource ' )->willReturn (true );
105
+ $ attribute ->method ('getIsVisible ' )
106
+ ->willReturn (true );
107
+ $ attribute ->method ('getIsGlobal ' )
108
+ ->willReturn (true );
109
+ $ attribute ->method ('getIsRequired ' )
110
+ ->willReturn (true );
111
+ $ attribute ->method ('getIsUnique ' )
112
+ ->willReturn (true );
113
+ $ attribute ->method ('getFrontendLabel ' )
114
+ ->willReturn ('frontend_label ' );
115
+ $ attribute ->method ('getApplyTo ' )
116
+ ->willReturn (['simple ' ]);
117
+ $ attribute ->method ('getDefaultValue ' )
118
+ ->willReturn ('default_value ' );
119
+ $ attribute ->method ('usesSource ' )
120
+ ->willReturn (true );
111
121
112
122
$ entityAttributes = [
113
123
[
@@ -123,38 +133,54 @@ protected function setUp(): void
123
133
$ attribute2 = clone $ attribute ;
124
134
$ attribute3 = clone $ attribute ;
125
135
126
- $ attribute1 ->expects ($ this ->any ())->method ('getId ' )->willReturn ('1 ' );
127
- $ attribute1 ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ('attr_code ' );
128
- $ attribute1 ->expects ($ this ->any ())->method ('getFrontendInput ' )->willReturn ('multiselect ' );
129
- $ attribute1 ->expects ($ this ->any ())->method ('isStatic ' )->willReturn (true );
130
-
131
- $ attribute2 ->expects ($ this ->any ())->method ('getId ' )->willReturn ('2 ' );
132
- $ attribute2 ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ('boolean_attribute ' );
133
- $ attribute2 ->expects ($ this ->any ())->method ('getFrontendInput ' )->willReturn ('boolean ' );
134
- $ attribute2 ->expects ($ this ->any ())->method ('isStatic ' )->willReturn (false );
135
-
136
- $ attribute3 ->expects ($ this ->any ())->method ('getId ' )->willReturn ('3 ' );
137
- $ attribute3 ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ('text_attribute ' );
138
- $ attribute3 ->expects ($ this ->any ())->method ('getFrontendInput ' )->willReturn ('text ' );
139
- $ attribute3 ->expects ($ this ->any ())->method ('isStatic ' )->willReturn (false );
140
-
141
- $ this ->entityModel ->expects ($ this ->any ())->method ('getEntityTypeId ' )->willReturn (3 );
142
- $ this ->entityModel ->expects ($ this ->any ())->method ('getAttributeOptions ' )->willReturnOnConsecutiveCalls (
143
- ['option1 ' , 'option2 ' ],
144
- ['yes ' => 1 , 'no ' => 0 ]
145
- );
146
- $ attrSetColFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ attrSetCollection );
147
- $ attrSetCollection ->expects ($ this ->any ())->method ('setEntityTypeFilter ' )->willReturn ([$ attributeSet ]);
148
- $ attrColFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ attrCollection );
149
- $ attrCollection ->expects ($ this ->any ())
150
- ->method ('setAttributeSetFilter ' )
136
+ $ attribute1 ->method ('getId ' )
137
+ ->willReturn ('1 ' );
138
+ $ attribute1 ->method ('getAttributeCode ' )
139
+ ->willReturn ('attr_code ' );
140
+ $ attribute1 ->method ('getFrontendInput ' )
141
+ ->willReturn ('multiselect ' );
142
+ $ attribute1 ->method ('isStatic ' )
143
+ ->willReturn (true );
144
+
145
+ $ attribute2 ->method ('getId ' )
146
+ ->willReturn ('2 ' );
147
+ $ attribute2 ->method ('getAttributeCode ' )
148
+ ->willReturn ('boolean_attribute ' );
149
+ $ attribute2 ->method ('getFrontendInput ' )
150
+ ->willReturn ('boolean ' );
151
+ $ attribute2 ->method ('isStatic ' )
152
+ ->willReturn (false );
153
+
154
+ $ attribute3 ->method ('getId ' )
155
+ ->willReturn ('3 ' );
156
+ $ attribute3 ->method ('getAttributeCode ' )
157
+ ->willReturn ('Text_attribute ' );
158
+ $ attribute3 ->method ('getFrontendInput ' )
159
+ ->willReturn ('text ' );
160
+ $ attribute3 ->method ('isStatic ' )
161
+ ->willReturn (false );
162
+
163
+ $ this ->entityModel ->method ('getEntityTypeId ' )
164
+ ->willReturn (3 );
165
+ $ this ->entityModel ->method ('getAttributeOptions ' )
166
+ ->willReturnOnConsecutiveCalls (
167
+ ['option1 ' , 'option2 ' ],
168
+ ['yes ' => 1 , 'no ' => 0 ]
169
+ );
170
+ $ attrSetColFactory ->method ('create ' )
171
+ ->willReturn ($ attrSetCollection );
172
+ $ attrSetCollection ->method ('setEntityTypeFilter ' )
173
+ ->willReturn ([$ attributeSet ]);
174
+ $ attrColFactory ->method ('create ' )
175
+ ->willReturn ($ attrCollection );
176
+ $ attrCollection ->method ('setAttributeSetFilter ' )
151
177
->willReturn ([$ attribute1 , $ attribute2 , $ attribute3 ]);
152
- $ attributeSet ->expects ($ this ->any ())->method ('getId ' )->willReturn (1 );
153
- $ attributeSet ->expects ($ this ->any ())->method ('getAttributeSetName ' )->willReturn ('attribute_set_name ' );
178
+ $ attributeSet ->method ('getId ' )
179
+ ->willReturn (1 );
180
+ $ attributeSet ->method ('getAttributeSetName ' )
181
+ ->willReturn ('attribute_set_name ' );
154
182
155
- $ attrCollection
156
- ->expects ($ this ->any ())
157
- ->method ('addFieldToFilter ' )
183
+ $ attrCollection ->method ('addFieldToFilter ' )
158
184
->with (
159
185
['main_table.attribute_id ' , 'main_table.attribute_code ' ],
160
186
[
@@ -193,19 +219,26 @@ protected function setUp(): void
193
219
'getConnection ' ,
194
220
]
195
221
);
196
- $ this ->select ->expects ($ this ->any ())->method ('from ' )->willReturnSelf ();
197
- $ this ->select ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
198
- $ this ->select ->expects ($ this ->any ())->method ('joinLeft ' )->willReturnSelf ();
199
- $ this ->connection ->expects ($ this ->any ())->method ('select ' )->willReturn ($ this ->select );
222
+ $ this ->select ->method ('from ' )
223
+ ->willReturnSelf ();
224
+ $ this ->select ->method ('where ' )
225
+ ->willReturnSelf ();
226
+ $ this ->select ->method ('joinLeft ' )
227
+ ->willReturnSelf ();
228
+ $ this ->connection ->method ('select ' )
229
+ ->willReturn ($ this ->select );
200
230
$ connection = $ this ->createMock (Mysql::class);
201
- $ connection ->expects ($ this ->any ())->method ('quoteInto ' )->willReturn ('query ' );
202
- $ this ->select ->expects ($ this ->any ())->method ('getConnection ' )->willReturn ($ connection );
203
- $ this ->connection ->expects ($ this ->any ())->method ('insertOnDuplicate ' )->willReturnSelf ();
204
- $ this ->connection ->expects ($ this ->any ())->method ('delete ' )->willReturnSelf ();
205
- $ this ->connection ->expects ($ this ->any ())->method ('quoteInto ' )->willReturn ('' );
206
- $ this ->connection
207
- ->expects ($ this ->any ())
208
- ->method ('fetchAll ' )
231
+ $ connection ->method ('quoteInto ' )
232
+ ->willReturn ('query ' );
233
+ $ this ->select ->method ('getConnection ' )
234
+ ->willReturn ($ connection );
235
+ $ this ->connection ->method ('insertOnDuplicate ' )
236
+ ->willReturnSelf ();
237
+ $ this ->connection ->method ('delete ' )
238
+ ->willReturnSelf ();
239
+ $ this ->connection ->method ('quoteInto ' )
240
+ ->willReturn ('' );
241
+ $ this ->connection ->method ('fetchAll ' )
209
242
->willReturn ($ entityAttributes );
210
243
211
244
$ this ->resource = $ this ->createPartialMock (
@@ -215,12 +248,10 @@ protected function setUp(): void
215
248
'getTableName ' ,
216
249
]
217
250
);
218
- $ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )->willReturn (
219
- $ this ->connection
220
- );
221
- $ this ->resource ->expects ($ this ->any ())->method ('getTableName ' )->willReturn (
222
- 'tableName '
223
- );
251
+ $ this ->resource ->method ('getConnection ' )
252
+ ->willReturn ($ this ->connection );
253
+ $ this ->resource ->method ('getTableName ' )
254
+ ->willReturn ('tableName ' );
224
255
225
256
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
226
257
$ this ->simpleType = $ this ->objectManagerHelper ->getObject (
@@ -233,9 +264,7 @@ protected function setUp(): void
233
264
]
234
265
);
235
266
236
- $ this ->abstractType = $ this ->getMockBuilder (
237
- \Magento \CatalogImportExport \Model \Import \Product \Type \AbstractType::class
238
- )
267
+ $ this ->abstractType = $ this ->getMockBuilder (AbstractType::class)
239
268
->disableOriginalConstructor ()
240
269
->getMockForAbstractClass ();
241
270
}
@@ -277,8 +306,10 @@ public function testIsRowValidSuccess()
277
306
{
278
307
$ rowData = ['_attribute_set ' => 'attribute_set_name ' ];
279
308
$ rowNum = 1 ;
280
- $ this ->entityModel ->expects ($ this ->any ())->method ('getRowScope ' )->willReturn (null );
281
- $ this ->entityModel ->expects ($ this ->never ())->method ('addRowError ' );
309
+ $ this ->entityModel ->method ('getRowScope ' )
310
+ ->willReturn (null );
311
+ $ this ->entityModel ->expects ($ this ->never ())
312
+ ->method ('addRowError ' );
282
313
$ this ->setPropertyValue (
283
314
$ this ->simpleType ,
284
315
'_attributes ' ,
@@ -296,8 +327,9 @@ public function testIsRowValidError()
296
327
'sku ' => 'sku '
297
328
];
298
329
$ rowNum = 1 ;
299
- $ this ->entityModel ->expects ($ this ->any ())->method ('getRowScope ' )->willReturn (1 );
300
- $ this ->entityModel ->expects ($ this ->once ())->method ('addRowError ' )
330
+ $ this ->entityModel ->method ('getRowScope ' )
331
+ ->willReturn (1 );
332
+ $ this ->entityModel ->method ('addRowError ' )
301
333
->with (
302
334
RowValidatorInterface::ERROR_VALUE_IS_REQUIRED ,
303
335
1 ,
0 commit comments