1313use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
1414use Magento \Catalog \Model \ResourceModel \Eav \Attribute as EavAttribute ;
1515use Magento \Catalog \Model \ResourceModel \Eav \AttributeFactory as EavAttributeFactory ;
16- use Magento \Store \Test \Unit \Helper \StoreInterfaceTestHelper ;
1716use Magento \Catalog \Ui \DataProvider \Product \Form \Modifier \Eav ;
1817use Magento \Eav \Api \Data \AttributeGroupInterface ;
1918use Magento \Eav \Model \Config ;
19+ use Magento \Eav \Test \Unit \Helper \AttributeGroupInterfaceTestHelper ;
2020use Magento \Eav \Model \Entity \Attribute \Group ;
2121use Magento \Eav \Model \Entity \Attribute \Source \SourceInterface ;
2222use Magento \Eav \Model \Entity \Type as EntityType ;
4242use Magento \Ui \DataProvider \EavValidationRules ;
4343use Magento \Ui \DataProvider \Mapper \FormElement as FormElementMapper ;
4444use Magento \Ui \DataProvider \Mapper \MetaProperties as MetaPropertiesMapper ;
45+ use PHPUnit \Framework \Attributes \DataProvider ;
4546use PHPUnit \Framework \MockObject \MockObject ;
4647
4748/**
@@ -130,6 +131,11 @@ class EavTest extends AbstractModifierTestCase
130131 * @var SearchCriteria|MockObject
131132 */
132133 private $ searchCriteriaMock ;
134+
135+ /**
136+ * @var SearchResultsInterface|MockObject
137+ */
138+ private $ attributeGroupSearchResultsMock ;
133139
134140 /**
135141 * @var SortOrderBuilder|MockObject
@@ -152,7 +158,7 @@ class EavTest extends AbstractModifierTestCase
152158 private $ searchResultsMock ;
153159
154160 /**
155- * @var Attribute|MockObject
161+ * @var Attribute
156162 */
157163 private $ eavAttributeMock ;
158164
@@ -172,7 +178,7 @@ class EavTest extends AbstractModifierTestCase
172178 protected $ currencyLocaleMock ;
173179
174180 /**
175- * @var ProductAttributeInterface|MockObject
181+ * @var Attribute
176182 */
177183 protected $ productAttributeMock ;
178184
@@ -229,23 +235,34 @@ protected function setUp(): void
229235 $ this ->metaPropertiesMapperMock = $ this ->createMock (MetaPropertiesMapper::class);
230236 $ this ->searchCriteriaBuilderMock = $ this ->createMock (SearchCriteriaBuilder::class);
231237 $ this ->attributeGroupRepositoryMock = $ this ->createMock (ProductAttributeGroupRepositoryInterface::class);
232- $ this ->attributeGroupMock = $ this ->createMock (AttributeGroupInterface::class);
238+ $ this ->attributeGroupMock = $ this ->createPartialMock (
239+ AttributeGroupInterfaceTestHelper::class,
240+ ['getAttributeGroupCode ' ]
241+ );
233242 $ this ->attributeRepositoryMock = $ this ->createMock (ProductAttributeRepositoryInterface::class);
234- $ this ->searchCriteriaMock = $ this ->createPartialMock (SearchCriteria::class, ['getItems ' ]);
243+ $ this ->searchCriteriaMock = $ this ->createMock (SearchCriteria::class);
244+ $ this ->attributeGroupSearchResultsMock = $ this ->createMock (SearchResultsInterface::class);
235245 $ this ->sortOrderBuilderMock = $ this ->createMock (SortOrderBuilder::class);
236246 $ this ->searchResultsMock = $ this ->createMock (SearchResultsInterface::class);
237247 $ this ->eavAttributeMock = $ this ->createPartialMock (
238248 Attribute::class,
239249 [
240- 'load ' ,
241250 'getApplyTo ' ,
242251 'getFrontendInput ' ,
243252 'getAttributeCode ' ,
244253 'usesSource ' ,
245254 'getSource ' ,
246255 ]
247256 );
248- $ this ->productAttributeMock = $ this ->createMock (ProductAttributeInterface::class);
257+ $ this ->productAttributeMock = $ this ->createPartialMock (
258+ Attribute::class,
259+ [
260+ 'getIsRequired ' ,
261+ 'getDefaultValue ' ,
262+ 'getAttributeCode ' ,
263+ 'getFrontendInput ' ,
264+ ]
265+ );
249266 $ this ->arrayManagerMock = $ this ->createMock (ArrayManager::class);
250267 $ this ->eavAttributeFactoryMock = $ this ->createPartialMock (
251268 EavAttributeFactory::class,
@@ -283,13 +300,13 @@ protected function setUp(): void
283300 $ this ->entityTypeMock ->expects ($ this ->any ())
284301 ->method ('getAttributeCollection ' )
285302 ->willReturn ($ this ->attributeCollectionMock );
286- $ this ->productMock -> expects ( $ this ->any ())
287- -> method ( ' getAttributes ' )
288- ->willReturn ([ $ this -> attributeMock ]);
289- $ this -> storeMock = $ this -> createPartialMock (StoreInterfaceTestHelper::class, [ ' getId ' ] );
290- $ this ->eavAttributeMock ->expects ($ this ->any ())
291- ->method ('load ' )
292- ->willReturnSelf ( );
303+ $ this ->storeMock = $ this ->createMock (StoreInterface::class);
304+ $ this -> storeManagerMock -> expects ( $ this -> any () )
305+ ->method ( ' isSingleStoreMode ' )
306+ -> willReturn ( true );
307+ $ this ->attributeGroupMock ->expects ($ this ->any ())
308+ ->method ('getAttributeGroupCode ' )
309+ ->willReturn ( ' product-details ' );
293310
294311 $ this ->eav =$ this ->getModel ();
295312 }
@@ -347,15 +364,18 @@ public function testModifyData()
347364 ->willReturn (4 );
348365 $ this ->productMock ->expects ($ this ->once ())->method ('getData ' )
349366 ->with (ProductAttributeInterface::CODE_PRICE )->willReturn ('19.9900 ' );
367+ $ this ->productMock ->expects ($ this ->any ())
368+ ->method ('getAttributes ' )
369+ ->willReturn ([$ this ->attributeMock ]);
350370
351371 $ this ->searchCriteriaBuilderMock ->expects ($ this ->any ())->method ('addFilter ' )
352372 ->willReturnSelf ();
353373 $ this ->searchCriteriaBuilderMock ->expects ($ this ->any ())->method ('create ' )
354374 ->willReturn ($ this ->searchCriteriaMock );
355- $ this ->attributeGroupRepositoryMock ->expects ($ this ->any ())->method ('getList ' )
356- ->willReturn ($ this ->searchCriteriaMock );
357- $ this ->searchCriteriaMock ->expects ($ this ->once ())->method ('getItems ' )
375+ $ this ->attributeGroupSearchResultsMock ->method ('getItems ' )
358376 ->willReturn ([$ this ->attributeGroupMock ]);
377+ $ this ->attributeGroupRepositoryMock ->expects ($ this ->any ())->method ('getList ' )
378+ ->willReturn ($ this ->attributeGroupSearchResultsMock );
359379 $ this ->sortOrderBuilderMock ->expects ($ this ->once ())->method ('setField ' )
360380 ->willReturnSelf ();
361381 $ this ->sortOrderBuilderMock ->expects ($ this ->once ())->method ('setAscendingDirection ' )
@@ -374,8 +394,6 @@ public function testModifyData()
374394 $ this ->attributeRepositoryMock ->expects ($ this ->once ())->method ('getList ' )
375395 ->with ($ this ->searchCriteriaMock )
376396 ->willReturn ($ this ->searchResultsMock );
377- $ this ->eavAttributeMock ->expects ($ this ->any ())->method ('getAttributeGroupCode ' )
378- ->willReturn ('product-details ' );
379397 $ this ->eavAttributeMock ->expects ($ this ->once ())->method ('getApplyTo ' )
380398 ->willReturn ([]);
381399 $ this ->eavAttributeMock ->expects ($ this ->once ())->method ('getFrontendInput ' )
@@ -398,8 +416,8 @@ public function testModifyData()
398416 * @param array $expectedCustomize
399417 * @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::isProductExists
400418 * @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::setupAttributeMeta
401- * @dataProvider setupAttributeMetaDataProvider
402419 */
420+ #[DataProvider('setupAttributeMetaDataProvider ' )]
403421 public function testSetupAttributeMetaDefaultAttribute (
404422 $ productId ,
405423 bool $ productRequired ,
@@ -432,17 +450,15 @@ public function testSetupAttributeMetaDefaultAttribute(
432450 $ this ->productAttributeMock ->method ('getIsRequired ' )->willReturn ($ productRequired );
433451 $ this ->productAttributeMock ->method ('getDefaultValue ' )->willReturn ('required_value ' );
434452 $ this ->productAttributeMock ->method ('getAttributeCode ' )->willReturn ('code ' );
435- $ this ->productAttributeMock ->method ('getValue ' )->willReturn ('value ' );
436453 $ this ->productAttributeMock ->method ('getFrontendInput ' )->willReturn ($ frontendInput );
437454
438- $ attributeMock = $ this ->createPartialMock (AttributeInterface::class, ['getValue ' ]);
439-
455+ $ attributeMock = $ this ->createStub (AttributeInterface::class);
440456 $ attributeMock ->method ('getValue ' )->willReturn ($ attrValue );
441457
442458 $ this ->productMock ->method ('getCustomAttribute ' )->willReturn ($ attributeMock );
443459 $ this ->eavAttributeMock ->method ('usesSource ' )->willReturn (true );
444460
445- $ attributeSource = $ this ->createMock (SourceInterface::class);
461+ $ attributeSource = $ this ->createStub (SourceInterface::class);
446462 $ attributeSource ->method ('getAllOptions ' )->willReturn ($ attributeOptions );
447463
448464 $ this ->eavAttributeMock ->method ('getSource ' )->willReturn ($ attributeSource );
0 commit comments