本文整理汇总了PHP中Magento\Customer\Api\CustomerRepositoryInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomerRepositoryInterface::expects方法的具体用法?PHP CustomerRepositoryInterface::expects怎么用?PHP CustomerRepositoryInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Api\CustomerRepositoryInterface
的用法示例。
在下文中一共展示了CustomerRepositoryInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExecute
/**
* @return void
*/
public function testExecute()
{
$formId = 'user_login';
$login = 'login';
$loginParams = ['username' => $login];
$customerId = 7;
$redirectUrl = 'http://magento.com/customer/account/login/';
$captchaValue = 'some-value';
$captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false);
$captcha->expects($this->once())->method('isRequired')->with($login)->willReturn(true);
$captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
$captcha->expects($this->once())->method('logAttempt')->with($login);
$this->helperMock->expects($this->once())->method('getCaptcha')->with($formId)->willReturn($captcha);
$response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$response->expects($this->once())->method('setRedirect')->with($redirectUrl);
$request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$request->expects($this->any())->method('getPost')->with('login')->willReturn($loginParams);
$controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
$controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
$this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, $formId)->willReturn($captchaValue);
$customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', ['getId'], [], '', false);
$customerDataMock->expects($this->once())->method('getId')->willReturn($customerId);
$this->customerRepositoryMock->expects($this->once())->method('get')->with($login)->willReturn($customerDataMock);
$this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId);
$this->messageManagerMock->expects($this->once())->method('addError')->with(__('Incorrect CAPTCHA'));
$this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->customerSessionMock->expects($this->once())->method('setUsername')->with($login);
$this->customerSessionMock->expects($this->once())->method('getBeforeAuthUrl')->willReturn(false);
$this->customerUrlMock->expects($this->once())->method('getLoginUrl')->willReturn($redirectUrl);
$this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
}
示例2: testSubscribe
public function testSubscribe()
{
$email = 'subscriber_email@magento.com';
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']);
$this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field');
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true);
$this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
$customerDataModel = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface');
$this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel);
$this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1);
$customerDataModel->expects($this->any())->method('getEmail')->willReturn($email);
$this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel);
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1);
$customerDataModel->expects($this->any())->method('getId')->willReturn(1);
$this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf();
$storeModel = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false);
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn('owner_email@magento.com');
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
$storeModel->expects($this->any())->method('getId')->willReturn(1);
$transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface');
$this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport);
$transport->expects($this->any())->method('sendMessage')->willReturnSelf();
$inlineTranslation = $this->getMock('Magento\\Framework\\Translate\\Inline\\StateInterface');
$inlineTranslation->expects($this->any())->method('resume')->willReturnSelf();
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
$this->assertEquals(1, $this->subscriber->subscribe($email));
}
示例3: testSaveActionWithException
public function testSaveActionWithException()
{
$this->formKeyValidatorMock->expects($this->once())->method('validate')->will($this->returnValue(true));
$this->customerSessionMock->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
$this->customerRepositoryMock->expects($this->any())->method('getById')->will($this->throwException(new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'customerId', 'value' => 'value']))));
$this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'customer/account/', []);
$this->messageManagerMock->expects($this->never())->method('addSuccess');
$this->messageManagerMock->expects($this->once())->method('addError')->with('Something went wrong while saving your subscription.');
$this->action->execute();
}
示例4: testExecute
/**
* @return void
*/
public function testExecute()
{
$customerId = 1;
$observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
$eventMock = $this->getMock('Magento\\Framework\\Event', ['getData'], [], '', false);
$observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
$eventMock->expects($this->once())->method('getData')->with('model')->willReturn($this->customerModelMock);
$this->customerModelMock->expects($this->once())->method('getId')->willReturn($customerId);
$this->customerRepositoryMock->expects($this->once())->method('getById')->willReturn($this->customerDataMock);
$this->customerDataMock->expects($this->once())->method('getId')->willReturn($customerId);
$this->accountManagementHelperMock->expects($this->once())->method('processUnlockData')->with($customerId);
$this->customerRepositoryMock->expects($this->once())->method('save')->with($this->customerDataMock);
$this->customerLoginSuccessObserver->execute($observerMock);
}
示例5: testExecute
/**
* @return void
*/
public function testExecute()
{
$username = 'customer@example.com';
$customerId = 1;
$observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
$eventMock = $this->getMock('Magento\\Framework\\Event', ['getData'], [], '', false);
$observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
$eventMock->expects($this->once())->method('getData')->with('username')->willReturn($username);
$this->customerRepositoryMock->expects($this->once())->method('get')->with($username)->willReturn($this->customerData);
$this->customerData->expects($this->exactly(2))->method('getId')->willReturn($customerId);
$this->accountManagementHelperMock->expects($this->once())->method('processCustomerLockoutData')->with($customerId);
$this->customerRepositoryMock->expects($this->once())->method('save')->with($this->customerData);
$this->observer->execute($observerMock);
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:17,代码来源:CustomerInvalidPasswordObserverTest.php
示例6: prepareInitiatePasswordReset
/**
* @param string $email
* @param string $templateIdentifier
* @param string $sender
* @param int $storeId
* @param int $customerId
* @param string $hash
*/
protected function prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash)
{
$websiteId = 1;
$dateTime = date(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
$customerData = ['key' => 'value'];
$customerName = 'Customer Name';
$this->store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
$this->store->expects($this->any())->method('getId')->willReturn($storeId);
$this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store);
$customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
$customer->expects($this->any())->method('getEmail')->willReturn($email);
$customer->expects($this->any())->method('getId')->willReturn($customerId);
$customer->expects($this->any())->method('getStoreId')->willReturn($storeId);
$this->customerRepository->expects($this->once())->method('get')->with($email, $websiteId)->willReturn($customer);
$this->customerRepository->expects($this->once())->method('save')->with($customer)->willReturnSelf();
$this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash);
$this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName);
$this->customerSecure->expects($this->any())->method('setRpToken')->with($hash)->willReturnSelf();
$this->customerSecure->expects($this->any())->method('setRpTokenCreatedAt')->with($dateTime)->willReturnSelf();
$this->customerSecure->expects($this->any())->method('addData')->with($customerData)->willReturnSelf();
$this->customerSecure->expects($this->any())->method('setData')->with('name', $customerName)->willReturnSelf();
$this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure);
$this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData);
$this->prepareEmailSend($email, $templateIdentifier, $sender, $storeId, $customerName);
}
示例7: testGetCustomerLoadCustomerFromService
/**
* test get customer method, method returns customer from service
*/
public function testGetCustomerLoadCustomerFromService()
{
$this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false));
$this->customerSessionMock->expects($this->once())->method('getId')->will($this->returnValue($this->customerId));
$this->customerRepositoryMock->expects($this->once())->method('getById')->with($this->equalTo($this->customerId))->will($this->returnValue($this->customerDataMock));
$this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer());
}
示例8: testBeforeDispatch
public function testBeforeDispatch()
{
$customerId = 1;
$customerGroupId = 1;
$this->appState->expects($this->any())->method('getAreaCode')->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
$this->request->expects($this->any())->method('isPost')->willReturn(true);
$customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
$customerMock->expects($this->any())->method('getGroupId')->willReturn($customerGroupId);
$this->customerRepository->expects($this->any())->method('getById')->with($customerId)->willReturn($customerMock);
$this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
$this->session->expects($this->any())->method('setCustomerData')->with($customerMock);
$this->session->expects($this->any())->method('setCustomerGroupId')->with($customerGroupId);
$this->session->expects($this->once())->method('regenerateId');
$this->notificationStorage->expects($this->any())->method('isExists')->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)->willReturn(true);
$this->plugin->beforeDispatch($this->abstractAction, $this->request);
}
示例9: testEditPostActionWithoutErrors
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testEditPostActionWithoutErrors()
{
$customerId = 24;
$address = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
$loadedCustomer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], 'loadedCustomer', false);
$loadedCustomer->expects($this->once())->method('getAddresses')->willReturn([$address, $address]);
$this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->redirectResultMock);
$this->formKeyValidator->expects($this->once())->method('validate')->willReturn(true);
$this->request->expects($this->once())->method('isPost')->willReturn(true);
$this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->customerExtractor->expects($this->once())->method('extract')->willReturn($this->customer);
$this->customer->expects($this->once())->method('setId')->with($customerId);
$this->customer->expects($this->once())->method('getAddresses')->willReturn(null);
$this->customerRepository->expects($this->exactly(2))->method('getById')->with($customerId)->willReturn($loadedCustomer);
$this->customer->expects($this->once())->method('setAddresses')->with([$address, $address]);
$this->request->expects($this->once())->method('getParam')->with('change_password')->willReturn(true);
$this->request->expects($this->at(2))->method('getPost')->with('current_password', null)->willReturn(123);
$this->request->expects($this->at(3))->method('getPost')->with('password', null)->willReturn(321);
$this->request->expects($this->at(4))->method('getPost')->with('password_confirmation', null)->willReturn(321);
$this->customerAccountManagement->expects($this->once())->method('changePassword');
$this->customerRepository->expects($this->once())->method('save');
$messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', [], [], '', false);
$messageCollection->expects($this->once())->method('getCount')->willReturn(0);
$this->messageManager->expects($this->once())->method('getMessages')->willReturn($messageCollection);
$this->messageManager->expects($this->once())->method('addSuccess')->with('You saved the account information.');
$this->redirectResultMock->expects($this->once())->method('setPath')->with('customer/account')->willReturn('http://test.com/customer/account/edit');
$this->assertSame($this->redirectResultMock, $this->getController()->execute());
}
示例10: testCreateAccountWithPasswordHashWithCustomerAddresses
public function testCreateAccountWithPasswordHashWithCustomerAddresses()
{
$websiteId = 1;
$addressId = 2;
$customerId = null;
$storeId = 1;
$hash = '4nj54lkj5jfi03j49f8bgujfgsd';
//Handle store
$store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
$store->expects($this->any())->method('getWebsiteId')->willReturn($websiteId);
//Handle address - existing and non-existing. Non-Existing should return null when call getId method
$existingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
$nonExistingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
//Ensure that existing address is not in use
$this->addressRepository->expects($this->atLeastOnce())->method("save")->withConsecutive(array($this->logicalNot($this->identicalTo($existingAddress))), array($this->identicalTo($nonExistingAddress)));
$existingAddress->expects($this->any())->method("getId")->willReturn($addressId);
//Expects that id for existing address should be unset
$existingAddress->expects($this->once())->method("setId")->with(null);
//Handle Customer calls
$customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
$customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId);
$customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
$customer->expects($this->any())->method("getId")->willReturn($customerId);
//Return Customer from customer repositoryå
$this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer);
$this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
$customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock();
$customerSecure->expects($this->once())->method('setRpToken')->with($hash);
$customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash);
$this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure);
$this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash);
$customer->expects($this->atLeastOnce())->method('getAddresses')->willReturn([$existingAddress, $nonExistingAddress]);
$this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store);
$this->assertSame($customer, $this->accountManagement->createAccountWithPasswordHash($customer, $hash));
}
示例11: testCreatePostActionRegistrationDisabled
/**
* @return void
*/
public function testCreatePostActionRegistrationDisabled()
{
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
$this->registration->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
$this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, '*/*/', [])->will($this->returnValue(false));
$this->customerRepository->expects($this->never())->method('save');
$this->model->execute();
}
示例12: testExecuteWithException
public function testExecuteWithException()
{
$customersIds = [10, 11, 12];
$this->customerCollectionMock->expects($this->any())->method('getAllIds')->willReturn($customersIds);
$this->customerRepositoryMock->expects($this->any())->method('getById')->willThrowException(new \Exception('Some message.'));
$this->messageManagerMock->expects($this->once())->method('addError')->with('Some message.');
$this->massAction->execute();
}
示例13: testExecuteWithExistentCustomer
/**
* @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExecuteWithExistentCustomer()
{
$customerId = 22;
$addressId = 11;
$subscription = 'true';
$postValue = ['customer' => ['entity_id' => $customerId, 'code' => 'value', 'coolness' => false, 'disable_auto_group_change' => 'false'], 'address' => ['_template_' => '_template_', $addressId => ['entity_id' => $addressId, 'default_billing' => 'true', 'default_shipping' => 'true', 'code' => 'value', 'coolness' => false, 'region' => 'region', 'region_id' => 'region_id']], 'subscription' => $subscription];
$filteredData = ['entity_id' => $customerId, 'code' => 'value', 'coolness' => false, 'disable_auto_group_change' => 'false'];
$addressFilteredData = ['entity_id' => $addressId, 'default_billing' => 'true', 'default_shipping' => 'true', 'code' => 'value', 'coolness' => false, 'region' => 'region', 'region_id' => 'region_id'];
$savedData = ['entity_id' => $customerId, 'darkness' => true, 'name' => 'Name', \Magento\Customer\Api\Data\CustomerInterface::DEFAULT_BILLING => false, \Magento\Customer\Api\Data\CustomerInterface::DEFAULT_SHIPPING => false];
$mergedData = ['entity_id' => $customerId, 'darkness' => true, 'name' => 'Name', 'code' => 'value', 'disable_auto_group_change' => 0, \Magento\Customer\Api\Data\CustomerInterface::DEFAULT_BILLING => $addressId, \Magento\Customer\Api\Data\CustomerInterface::DEFAULT_SHIPPING => $addressId, 'confirmation' => false, 'sendemail_store_id' => '1', 'id' => $customerId];
$mergedAddressData = ['entity_id' => $addressId, 'default_billing' => true, 'default_shipping' => true, 'code' => 'value', 'region' => ['region' => 'region', 'region_id' => 'region_id'], 'region_id' => 'region_id', 'id' => $addressId];
/** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $formMock */
$attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
$attributeMock->expects($this->exactly(2))->method('getAttributeCode')->willReturn('coolness');
$attributeMock->expects($this->exactly(2))->method('getFrontendInput')->willReturn('int');
$attributes = [$attributeMock];
$this->requestMock->expects($this->exactly(3))->method('getPostValue')->willReturn($postValue);
$this->requestMock->expects($this->exactly(3))->method('getPost')->willReturnMap([['customer', null, $postValue['customer']], ['address', null, $postValue['address']], ['subscription', null, $subscription]]);
/** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject $formMock */
$formMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock();
$this->formFactoryMock->expects($this->exactly(2))->method('create')->willReturnMap([[\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE, [], $formMock], [\Magento\Customer\Api\AddressMetadataInterface::ENTITY_TYPE_ADDRESS, 'adminhtml_customer_address', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE, [], $formMock]]);
$formMock->expects($this->exactly(2))->method('extractData')->willReturnMap([[$this->requestMock, 'customer', true, $filteredData], [$this->requestMock, 'address/' . $addressId, true, $addressFilteredData]]);
/** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */
$objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
$this->objectFactoryMock->expects($this->exactly(2))->method('create')->with(['data' => $postValue])->willReturn($objectMock);
$objectMock->expects($this->exactly(2))->method('getData')->willReturnMap([['customer', null, $postValue['customer']], ['address/' . $addressId, null, $postValue['address'][$addressId]]]);
$formMock->expects($this->exactly(2))->method('getAttributes')->willReturn($attributes);
/** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */
$customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
$this->customerDataFactoryMock->expects($this->once())->method('create')->willReturn($customerMock);
$this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($customerMock);
$this->customerMapperMock->expects($this->once())->method('toFlatArray')->with($customerMock)->willReturn($savedData);
$addressMock = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
$this->addressDataFactoryMock->expects($this->once())->method('create')->willReturn($addressMock);
$this->dataHelperMock->expects($this->exactly(2))->method('populateWithArray')->willReturnMap([[$customerMock, $mergedData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface', $this->dataHelperMock], [$addressMock, $mergedAddressData, '\\Magento\\Customer\\Api\\Data\\AddressInterface', $this->dataHelperMock]]);
$customerMock->expects($this->once())->method('setAddresses')->with([$addressMock])->willReturnSelf();
$this->customerRepositoryMock->expects($this->once())->method('save')->with($customerMock)->willReturnSelf();
$customerEmail = 'customer@email.com';
$customerMock->expects($this->once())->method('getEmail')->willReturn($customerEmail);
$this->emailNotificationMock->expects($this->once())->method('credentialsChanged')->with($customerMock, $customerEmail)->willReturnSelf();
$this->authorizationMock->expects($this->once())->method('isAllowed')->with(null)->willReturn(true);
/** @var \Magento\Newsletter\Model\Subscriber|\PHPUnit_Framework_MockObject_MockObject $subscriberMock */
$subscriberMock = $this->getMockBuilder('Magento\\Newsletter\\Model\\Subscriber')->disableOriginalConstructor()->getMock();
$this->subscriberFactoryMock->expects($this->once())->method('create')->with()->willReturn($subscriberMock);
$subscriberMock->expects($this->once())->method('subscribeCustomerById')->with($customerId);
$subscriberMock->expects($this->never())->method('unsubscribeCustomerById');
$this->sessionMock->expects($this->once())->method('unsCustomerFormData');
$this->registryMock->expects($this->once())->method('register')->with(\Magento\Customer\Controller\RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
$this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('You saved the customer.'))->willReturnSelf();
$this->requestMock->expects($this->once())->method('getParam')->with('back', false)->willReturn(true);
/** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
$redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
$this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
$redirectMock->expects($this->once())->method('setPath')->with('customer/*/edit', ['id' => $customerId, '_current' => true])->willReturn(true);
$this->assertEquals($redirectMock, $this->model->execute());
}
示例14: testExecuteException
public function testExecuteException()
{
$exception = new \Exception('Exception message');
$this->prepareMocksForTesting();
$this->customerData->expects($this->once())->method('getDefaultBilling')->willReturn(false);
$this->customerRepository->expects($this->once())->method('save')->with($this->customerData)->willThrowException($exception);
$this->messageManager->expects($this->once())->method('addError')->with('[Customer ID: 12] We can\'t save the customer.');
$this->logger->expects($this->once())->method('critical')->with($exception);
$this->prepareMocksForErrorMessagesProcessing();
$this->assertSame($this->resultJson, $this->controller->execute());
}
示例15: testExecuteWithException
public function testExecuteWithException()
{
$token = 'token';
$customerId = '11';
$password = 'password';
$passwordConfirmation = 'password';
$email = 'email@email.com';
$this->requestMock->expects($this->exactly(2))->method('getQuery')->willReturnMap([['token', $token], ['id', $customerId]]);
$this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['password', $password], ['password_confirmation', $passwordConfirmation]]);
/** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */
$customerMock = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
$this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($customerMock);
$customerMock->expects($this->once())->method('getEmail')->willReturn($email);
$this->accountManagementMock->expects($this->once())->method('resetPassword')->with($email, $token, $password)->willThrowException(new \Exception('Exception.'));
$this->messageManagerMock->expects($this->once())->method('addError')->with(__('Something went wrong while saving the new password.'))->willReturnSelf();
/** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
$redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
$this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
$redirectMock->expects($this->once())->method('setPath')->with('*/*/createPassword', ['id' => $customerId, 'token' => $token])->willReturnSelf();
$this->assertEquals($redirectMock, $this->model->execute());
}