1313use Magento \Eav \Model \AttributeDataFactory ;
1414use Magento \Eav \Model \Entity \AbstractEntity ;
1515use Magento \Eav \Model \Validator \Attribute \Data ;
16+ use Magento \Framework \App \ObjectManager ;
1617use Magento \Framework \DataObject ;
1718use Magento \Framework \Model \AbstractModel ;
1819use Magento \Framework \ObjectManagerInterface ;
@@ -35,6 +36,11 @@ class DataTest extends TestCase
3536 */
3637 private $ model ;
3738
39+ /**
40+ * @var \Magento\Eav\Model\Config|MockObject
41+ */
42+ private $ eavConfigMock ;
43+
3844 /**
3945 * @inheritdoc
4046 */
@@ -49,7 +55,12 @@ protected function setUp(): void
4955 ]
5056 )
5157 ->getMock ();
52-
58+ $ this ->createMock (ObjectManagerInterface::class);
59+ ObjectManager::setInstance ($ this ->createMock (ObjectManagerInterface::class));
60+ $ this ->eavConfigMock = $ this ->getMockBuilder (\Magento \Eav \Model \Config::class)
61+ ->onlyMethods (['getEntityType ' ])
62+ ->disableOriginalConstructor ()
63+ ->getMock ();
5364 $ this ->model = new Data ($ this ->attrDataFactory );
5465 }
5566
@@ -205,13 +216,17 @@ public function testIsValidAttributesFromCollection(): void
205216 'is_visible ' => true ,
206217 ]
207218 );
219+ $ entityTypeCode = 'entity_type_code ' ;
208220 $ collection = $ this ->getMockBuilder (DataObject::class)
209221 ->addMethods (['getItems ' ])->getMock ();
210222 $ collection ->expects ($ this ->once ())->method ('getItems ' )->willReturn ([$ attribute ]);
211223 $ entityType = $ this ->getMockBuilder (DataObject::class)
212- ->addMethods (['getAttributeCollection ' ])
224+ ->addMethods (['getAttributeCollection ' , ' getEntityTypeCode ' ])
213225 ->getMock ();
226+ $ entityType ->expects ($ this ->atMost (2 ))->method ('getEntityTypeCode ' )->willReturn ($ entityTypeCode );
214227 $ entityType ->expects ($ this ->once ())->method ('getAttributeCollection ' )->willReturn ($ collection );
228+ $ this ->eavConfigMock ->expects ($ this ->once ())->method ('getEntityType ' )
229+ ->with ($ entityTypeCode )->willReturn ($ entityType );
215230 $ entity = $ this ->_getEntityMock ();
216231 $ entity ->expects ($ this ->once ())->method ('getResource ' )->willReturn ($ resource );
217232 $ entity ->expects ($ this ->once ())->method ('getEntityType ' )->willReturn ($ entityType );
@@ -235,7 +250,7 @@ public function testIsValidAttributesFromCollection(): void
235250 )->willReturn (
236251 $ dataModel
237252 );
238- $ validator = new Data ($ attrDataFactory );
253+ $ validator = new Data ($ attrDataFactory, $ this -> eavConfigMock );
239254
240255 $ validator ->setData (['attribute ' => 'new_test_data ' ]);
241256 $ this ->assertTrue ($ validator ->isValid ($ entity ));
0 commit comments