protected function setUp() { parent::setUp(); $this->eavConfigMock = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); $this->eavValidationRulesMock = $this->getMockBuilder(EavValidationRules::class)->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->groupCollectionFactoryMock = $this->getMockBuilder(GroupCollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->groupCollectionMock = $this->getMockBuilder(GroupCollection::class)->disableOriginalConstructor()->getMock(); $this->attributeMock = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock(); $this->groupMock = $this->getMockBuilder(Group::class)->disableOriginalConstructor()->setMethods(['getAttributeGroupCode'])->getMock(); $this->entityTypeMock = $this->getMockBuilder(EntityType::class)->disableOriginalConstructor()->getMock(); $this->attributeCollectionMock = $this->getMockBuilder(AttributeCollection::class)->disableOriginalConstructor()->getMock(); $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMockForAbstractClass(); $this->formElementMapperMock = $this->getMockBuilder(FormElementMapper::class)->disableOriginalConstructor()->getMock(); $this->metaPropertiesMapperMock = $this->getMockBuilder(MetaPropertiesMapper::class)->disableOriginalConstructor()->getMock(); $this->groupCollectionFactoryMock->expects($this->any())->method('create')->willReturn($this->groupCollectionMock); $this->groupCollectionMock->expects($this->any())->method('setAttributeSetFilter')->willReturnSelf(); $this->groupCollectionMock->expects($this->any())->method('setSortOrder')->willReturnSelf(); $this->groupCollectionMock->expects($this->any())->method('load')->willReturnSelf(); $this->groupCollectionMock->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator([$this->groupMock])); $this->attributeCollectionMock->expects($this->any())->method('addFieldToSelect')->willReturnSelf(); $this->attributeCollectionMock->expects($this->any())->method('load')->willReturnSelf(); $this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn($this->entityTypeMock); $this->entityTypeMock->expects($this->any())->method('getAttributeCollection')->willReturn($this->attributeCollectionMock); $this->productMock->expects($this->any())->method('getAttributes')->willReturn([$this->attributeMock]); }
/** * Prepare Eav config mock object * * @return \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject */ protected function prepareEavConfig() { $attributeMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['getAttributeCode', 'getBackend', '__wakeup'], [], '', false); $attributeMock->expects($this->any())->method('getAttributeCode')->willReturn('entity_id'); $attributeMock->expects($this->any())->method('getBackend')->willReturn($this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', [], [], '', false)); $this->eavConfigType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', ['getEntityIdField', 'getId', 'getEntityTable', '__wakeup'], [], '', false); $this->eavConfigType->expects($this->any())->method('getEntityIdField')->willReturn(false); $this->eavConfigType->expects($this->any())->method('getId')->willReturn(false); $this->eavConfigType->expects($this->any())->method('getEntityTable')->willReturn('customer_address_entity'); $eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', ['getEntityType', 'getEntityAttributeCodes', 'getAttribute'], [], '', false); $eavConfig->expects($this->any())->method('getEntityType')->with('customer_address')->willReturn($this->eavConfigType); $eavConfig->expects($this->any())->method('getEntityAttributeCodes')->with($this->eavConfigType)->willReturn(['entity_type_id', 'attribute_set_id', 'created_at', 'updated_at', 'parent_id', 'increment_id', 'entity_id']); $eavConfig->expects($this->any())->method('getAttribute')->willReturnMap([[$this->eavConfigType, 'entity_type_id', $attributeMock], [$this->eavConfigType, 'attribute_set_id', $attributeMock], [$this->eavConfigType, 'created_at', $attributeMock], [$this->eavConfigType, 'updated_at', $attributeMock], [$this->eavConfigType, 'parent_id', $attributeMock], [$this->eavConfigType, 'increment_id', $attributeMock], [$this->eavConfigType, 'entity_id', $attributeMock]]); return $eavConfig; }
protected function setUp() { parent::setUp(); $this->objectManager = new ObjectManager($this); $this->eavConfigMock = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); $this->eavValidationRulesMock = $this->getMockBuilder(EavValidationRules::class)->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->groupCollectionFactoryMock = $this->getMockBuilder(GroupCollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->groupCollectionMock = $this->getMockBuilder(GroupCollection::class)->disableOriginalConstructor()->getMock(); $this->attributeMock = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock(); $this->groupMock = $this->getMockBuilder(Group::class)->disableOriginalConstructor()->setMethods(['getAttributeGroupCode'])->getMock(); $this->entityTypeMock = $this->getMockBuilder(EntityType::class)->disableOriginalConstructor()->getMock(); $this->attributeCollectionMock = $this->getMockBuilder(AttributeCollection::class)->disableOriginalConstructor()->getMock(); $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMockForAbstractClass(); $this->formElementMapperMock = $this->getMockBuilder(FormElementMapper::class)->disableOriginalConstructor()->getMock(); $this->metaPropertiesMapperMock = $this->getMockBuilder(MetaPropertiesMapper::class)->disableOriginalConstructor()->getMock(); $this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class)->disableOriginalConstructor()->getMock(); $this->attributeGroupRepositoryMock = $this->getMockBuilder(ProductAttributeGroupRepositoryInterface::class)->getMockForAbstractClass(); $this->attributeGroupMock = $this->getMockBuilder(AttributeGroupInterface::class)->setMethods(['getAttributeGroupCode', 'getApplyTo'])->getMockForAbstractClass(); $this->attributeRepositoryMock = $this->getMockBuilder(ProductAttributeRepositoryInterface::class)->getMockForAbstractClass(); $this->searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->setMethods(['getItems'])->getMock(); $this->sortOrderBuilderMock = $this->getMockBuilder(SortOrderBuilder::class)->disableOriginalConstructor()->getMock(); $this->searchResultsMock = $this->getMockBuilder(SearchResultsInterface::class)->getMockForAbstractClass(); $this->eavAttributeMock = $this->getMockBuilder(Attribute::class)->setMethods(['getAttributeGroupCode', 'getApplyTo', 'getFrontendInput', 'getAttributeCode'])->disableOriginalConstructor()->getMock(); $this->groupCollectionFactoryMock->expects($this->any())->method('create')->willReturn($this->groupCollectionMock); $this->groupCollectionMock->expects($this->any())->method('setAttributeSetFilter')->willReturnSelf(); $this->groupCollectionMock->expects($this->any())->method('setSortOrder')->willReturnSelf(); $this->groupCollectionMock->expects($this->any())->method('load')->willReturnSelf(); $this->groupCollectionMock->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator([$this->groupMock])); $this->attributeCollectionMock->expects($this->any())->method('addFieldToSelect')->willReturnSelf(); $this->attributeCollectionMock->expects($this->any())->method('load')->willReturnSelf(); $this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn($this->entityTypeMock); $this->entityTypeMock->expects($this->any())->method('getAttributeCollection')->willReturn($this->attributeCollectionMock); $this->productMock->expects($this->any())->method('getAttributes')->willReturn([$this->attributeMock]); $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['load', 'getId', 'getConfig', 'getBaseCurrencyCode'])->getMockForAbstractClass(); $this->currencyMock = $this->getMockBuilder(Currency::class)->disableOriginalConstructor()->setMethods(['toCurrency'])->getMock(); $this->currencyLocaleMock = $this->getMockBuilder(CurrencyLocale::class)->disableOriginalConstructor()->setMethods(['getCurrency'])->getMock(); $this->eav = $this->getModel(); $this->objectManager->setBackwardCompatibleProperty($this->eav, 'localeCurrency', $this->currencyLocaleMock); }
public function testNextValue() { $this->type->expects($this->once())->method('fetchNewIncrementId')->with(1)->willReturn(2); $this->eavConfig->expects($this->once())->method('getEntityType')->with('order')->willReturn($this->type); $this->assertEquals(2, $this->model->getNextValue(1)); }