protected function setUp() { $this->actionValidatorMock = $this->getMock('\\Magento\\Framework\\Model\\ActionValidator\\RemoveAction', [], [], '', false); $this->contextMock = new \Magento\Framework\Model\Context($this->getMock('Psr\\Log\\LoggerInterface'), $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false), $this->getMock('Magento\\Framework\\App\\CacheInterface', [], [], '', false), $this->getMock('Magento\\Framework\\App\\State', [], [], '', false), $this->actionValidatorMock); $this->registryMock = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $this->resourceMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', ['_construct', '_getReadAdapter', '_getWriteAdapter', '__wakeup', 'commit', 'delete', 'getIdFieldName', 'rollBack'], [], '', false); $this->resourceCollectionMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db', [], [], '', false); $this->metadataServiceMock = $this->getMockBuilder('Magento\\Framework\\Api\\MetadataServiceInterface')->getMock(); $this->metadataServiceMock->expects($this->any())->method('getCustomAttributesMetadata')->willReturn([new \Magento\Framework\Object(['attribute_code' => 'attribute1']), new \Magento\Framework\Object(['attribute_code' => 'attribute2']), new \Magento\Framework\Object(['attribute_code' => 'attribute3'])]); $this->attributeDataBuilderMock = $this->getMockBuilder('Magento\\Framework\\Api\\AttributeDataBuilder')->disableOriginalConstructor()->getMock(); $this->model = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractExtensibleModel', [$this->contextMock, $this->registryMock, $this->metadataServiceMock, $this->attributeDataBuilderMock, $this->resourceMock, $this->resourceCollectionMock]); }
/** * Receive a list of EAV attributes using provided metadata service. * * Can be used in child classes, which represent EAV entities. * * @param \Magento\Framework\Api\MetadataServiceInterface $metadataService * @return string[] */ protected function getEavAttributesCodes(\Magento\Framework\Api\MetadataServiceInterface $metadataService) { $attributeCodes = []; $customAttributesMetadata = $metadataService->getCustomAttributesMetadata(get_class($this)); if (is_array($customAttributesMetadata)) { /** @var $attribute \Magento\Framework\Api\MetadataObjectInterface */ foreach ($customAttributesMetadata as $attribute) { $attributeCodes[] = $attribute->getAttributeCode(); } } return $attributeCodes; }