protected function setUp() { $helper = $this->getMockBuilder('Mage_Customer_Helper_Data')->getMock(); $helper->expects($this->any())->method('__')->will($this->returnArgument(0)); $this->_customerFactory = $this->getMockBuilder('Mage_Customer_Model_Customer_Factory')->disableOriginalConstructor()->setMethods(array('create'))->getMock(); $this->_addressFactory = $this->getMockBuilder('Mage_Customer_Model_Address_Factory')->disableOriginalConstructor()->setMethods(array('create'))->getMock(); $this->_customer = $this->getMockBuilder('Mage_Customer_Model_Customer')->setMethods(array('save', 'generatePassword', 'getOrigData', 'sendNewAccountEmail', 'getConfirmation', 'getPrimaryAddress', 'getAddresses', 'getAdditionalAddresses', 'load', 'getId', 'changePassword', 'sendPasswordReminderEmail', 'addAddress', 'getAddressItemById', 'getAddressesCollection'))->disableOriginalConstructor()->getMock(); $this->_customerFactory->expects($this->any())->method('create')->will($this->returnValue($this->_customer)); $this->_address = $this->_createAddress(true, null); $this->_addressFactory->expects($this->any())->method('create')->will($this->returnValue($this->_address)); $this->_service = new Mage_Customer_Service_Customer($helper, $this->_customerFactory, $this->_addressFactory); }
/** * Load customer by its ID * * @param int|string $customerId * @return Mage_Customer_Model_Customer * @throws Mage_Core_Exception */ protected function _loadCustomerById($customerId) { $customer = $this->_customerFactory->create(); $customer->load($customerId); if (!$customer->getId()) { throw new Mage_Core_Exception($this->_translateHelper->__("The customer with the specified ID not found.")); } return $customer; }
/** * Test beforeSave and afterSave callback * * @magentoDataFixture Mage/Customer/_files/customer.php */ public function testCallback() { $customer = $this->_customerFactory->create()->load(1); $customerData = array('firstname' => 'Updated name'); $customer->addData($customerData); $addressData = array(array('firstname' => 'John', 'lastname' => 'Smith', 'street' => 'Green str, 67', 'country_id' => 'AL', 'city' => 'CityM', 'postcode' => '75477', 'telephone' => '3468676')); $callbackCount = 0; $callback = function ($actualCustomer, $actualData, $actualAddresses) use($customer, $customerData, $addressData, &$callbackCount) { $callbackCount++; // Remove updated_at as in afterSave updated_at may be changed $expectedCustomerData = $customer->getData(); unset($expectedCustomerData['updated_at']); PHPUnit_Framework_Assert::assertEquals($expectedCustomerData, $actualCustomer->toArray(array_keys($expectedCustomerData))); PHPUnit_Framework_Assert::assertEquals($customerData, $actualData); PHPUnit_Framework_Assert::assertEquals($addressData, $actualAddresses); }; $this->_model->setBeforeSaveCallback($callback); $this->_model->setAfterSaveCallback($callback); $this->_model->update(1, $customerData, $addressData); $this->assertEquals(2, $callbackCount, 'Not all expected callbacks were called.'); }