/**
  * Retrieve all necessary objects mocks which used inside customer storage
  *
  * @return array
  */
 protected function _getModelDependencies()
 {
     $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from'])->getMock();
     $select->expects($this->any())->method('from')->will($this->returnCallback([$this, 'validateFrom']));
     $customerCollection = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->setMethods(['load', 'removeAttributeToSelect', 'getResource', 'getSelect'])->getMock();
     $resourceStub = new \Magento\Framework\DataObject();
     $resourceStub->setEntityTable($this->_entityTable);
     $customerCollection->expects($this->once())->method('getResource')->will($this->returnValue($resourceStub));
     $customerCollection->expects($this->once())->method('getSelect')->will($this->returnValue($select));
     $byPagesIterator = $this->getMock('stdClass', ['iterate']);
     $byPagesIterator->expects($this->once())->method('iterate')->will($this->returnCallback([$this, 'iterate']));
     return ['customer_collection' => $customerCollection, 'collection_by_pages_iterator' => $byPagesIterator, 'page_size' => 10];
 }
 /**
  * @param string $attributeCode
  * @param int $attributeSetId
  * @param array $productData
  * @param array $productOrigData
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @dataProvider productAttributesDataProvider
  */
 public function testSave($attributeCode, $attributeSetId, $productData, $productOrigData)
 {
     $object = $this->getMock('Magento\\Catalog\\Model\\Product', ['getOrigData', '__wakeup', 'beforeSave', 'afterSave', 'validateBeforeSave'], [], '', false);
     $object->setEntityTypeId(1);
     foreach ($productData as $key => $value) {
         $object->setData($key, $value);
     }
     $object->expects($this->any())->method('getOrigData')->will($this->returnValue($productOrigData));
     $entityType = new \Magento\Framework\DataObject();
     $entityType->setEntityTypeCode('test');
     $entityType->setEntityTypeId(0);
     $entityType->setEntityTable('table');
     $attributes = $this->_getAttributes();
     $attribute = $this->_getAttributeMock($attributeCode, $attributeSetId);
     /** @var $backendModel \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend */
     $backendModel = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', ['getBackend', 'getBackendTable', 'getAffectedFields', 'isStatic', 'getEntityValueId']);
     $backendModel->expects($this->once())->method('getAffectedFields')->will($this->returnValue(['test_table' => [['value_id' => 0, 'attribute_id' => $attributeCode]]]));
     $backendModel->expects($this->any())->method('isStatic')->will($this->returnValue(false));
     $backendModel->expects($this->never())->method('getEntityValueId');
     $backendModel->setAttribute($attribute);
     $attribute->expects($this->any())->method('getBackend')->will($this->returnValue($backendModel));
     $attribute->setId(222);
     $attributes[$attributeCode] = $attribute;
     $eavConfig = $this->getMockBuilder('Magento\\Eav\\Model\\Config')->disableOriginalConstructor()->getMock();
     $objectManager = new ObjectManager($this);
     $this->entitySnapshot->expects($this->once())->method('isModified')->willReturn(true);
     $this->entitySnapshot->expects($this->once())->method('registerSnapshot')->with($object);
     $this->entityRelationComposite->expects($this->once())->method('processRelations')->with($object);
     $arguments = $objectManager->getConstructArguments('Magento\\Eav\\Model\\Entity\\VersionControl\\AbstractEntity', ['eavConfig' => $eavConfig, 'entitySnapshot' => $this->entitySnapshot, 'entityRelationComposite' => $this->entityRelationComposite, 'data' => ['type' => $entityType, 'entityTable' => 'entityTable', 'attributesByCode' => $attributes]]);
     /** @var $model AbstractEntity|\PHPUnit_Framework_MockObject_MockObject */
     $model = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\VersionControl\\AbstractEntity')->setConstructorArgs($arguments)->setMethods(['_getValue', 'beginTransaction', 'commit', 'rollback', 'getConnection'])->getMock();
     $model->expects($this->any())->method('_getValue')->will($this->returnValue($eavConfig));
     $model->expects($this->any())->method('getConnection')->will($this->returnValue($this->_getConnectionMock()));
     $eavConfig->expects($this->any())->method('getAttribute')->will($this->returnCallback(function ($entityType, $attributeCode) use($attributes) {
         return $entityType && isset($attributes[$attributeCode]) ? $attributes[$attributeCode] : null;
     }));
     $model->isPartialSave(true);
     $model->save($object);
 }
 public function testWalkAttributes()
 {
     $objectManager = new ObjectManager($this);
     $code = 'test_attr';
     $set = 10;
     $object = $this->getMock('Magento\\Catalog\\Model\\Product', ['__wakeup'], [], '', false);
     $object->setData('test_attr', 'test_attr');
     $object->setData('attribute_set_id', $set);
     $entityType = new \Magento\Framework\DataObject();
     $entityType->setEntityTypeCode('test');
     $entityType->setEntityTypeId(0);
     $entityType->setEntityTable('table');
     $attributes = $this->_getAttributes();
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['isInSet', 'getBackend', '__wakeup'], [], '', false);
     $attribute->setAttributeId($code);
     $attribute->setAttributeCode($code);
     $attribute->expects($this->once())->method('isInSet')->with($this->equalTo($set))->will($this->returnValue(false));
     $attributes[$code] = $attribute;
     /** @var $model \Magento\Catalog\Model\ResourceModel\AbstractResource */
     $arguments = $objectManager->getConstructArguments('Magento\\Catalog\\Model\\ResourceModel\\AbstractResource');
     $model = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\AbstractResource', ['getAttributesByCode'], $arguments);
     $model->expects($this->once())->method('getAttributesByCode')->will($this->returnValue($attributes));
     $model->walkAttributes('backend/afterSave', [$object]);
 }