public function testAfterSave() { $addressId = 1; $attributeCode = 'attribute_code'; $defaultBilling = 'default billing address'; $object = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->setMethods(array('getDefaultBilling', 'getAddresses', 'setDefaultBilling'))->getMock(); $address = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->setMethods(array('getPostIndex', 'getId'))->getMock(); $attribute = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(array('__wakeup', 'getEntity', 'getAttributeCode'))->disableOriginalConstructor()->getMockForAbstractClass(); $entity = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\AbstractEntity')->setMethods(array('saveAttribute'))->disableOriginalConstructor()->getMockForAbstractClass(); $attribute->expects($this->once())->method('getEntity')->will($this->returnValue($entity)); $attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode)); $entity->expects($this->once())->method('saveAttribute')->with($this->logicalOr($object, $attributeCode)); $address->expects($this->once())->method('getPostIndex')->will($this->returnValue($defaultBilling)); $address->expects($this->once())->method('getId')->will($this->returnValue($addressId)); $object->expects($this->once())->method('getDefaultBilling')->will($this->returnValue($defaultBilling)); $object->expects($this->once())->method('setDefaultBilling')->with($addressId)->will($this->returnSelf()); $object->expects($this->once())->method('getAddresses')->will($this->returnValue(array($address))); /** @var \Magento\Framework\Object $object */ /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */ $this->testable->setAttribute($attribute); $this->testable->afterSave($object); }
/** * get or create attribute data for given object * * @param Billing $object * @return \Shopware\Models\Attribute\CustomerBilling * @throws Exception */ public function getOrCreateBillingAttribute($object) { if ($attribute = $object->getAttribute()) { return $attribute; } if ($object instanceof Shopware\Models\Customer\Billing) { if (!($attribute = Shopware()->Models()->getRepository('Shopware\\Models\\Attribute\\CustomerBilling')->findOneBy(array('customerBillingId' => $object->getId())))) { $attribute = new Shopware\Models\Attribute\CustomerBilling(); } } else { throw new Exception('Unknown attribute base class'); } $object->setAttribute($attribute); return $attribute; }