/** * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testCreateAddressFromModelWithCustomerId() { $defaultBillingId = 1; $defaultShippingId = 1; $customerId = 1; $attributeCode = 'attribute_code'; $addressModelMock = $this->getAddressMockForCreate(); $addressModelMock->expects($this->once())->method('getId')->will($this->returnValue(null)); $addressModelMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId)); $addressModelMock->expects($this->any())->method('getParentId'); $getData = function ($key, $index = null) use($attributeCode, $customerId) { $result = null; switch ($key) { case $attributeCode: $result = 'some_data'; break; case 'customer_id': $result = $customerId; break; } return $result; }; $addressModelMock->expects($this->any())->method('getData')->will($this->returnCallback($getData)); $attributeMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', array('getAttributeCode'), array(), '', false); $attributeMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode)); $addressMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Address', array(), array(), '', false); $this->addressMetadataServiceMock->expects($this->once())->method('getAllAttributesMetadata')->will($this->returnValue(array($attributeMock))); $this->addressBuilderMock->expects($this->once())->method('create')->will($this->returnValue($addressMock)); $this->addressBuilderMock->expects($this->once())->method('setCustomerId')->with($this->equalTo($customerId)); $this->assertEquals($addressMock, $this->model->createAddressFromModel($addressModelMock, $defaultBillingId, $defaultShippingId)); }