当前位置: 首页>>代码示例>>PHP>>正文


PHP CustomerFactory::expects方法代码示例

本文整理汇总了PHP中Magento\Customer\Model\CustomerFactory::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomerFactory::expects方法的具体用法?PHP CustomerFactory::expects怎么用?PHP CustomerFactory::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Model\CustomerFactory的用法示例。


在下文中一共展示了CustomerFactory::expects方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSave

 /**
  * @param $addressId
  * @param $isDefaultBilling
  * @param $isDefaultShipping
  *
  * @dataProvider getSaveDataProvider
  */
 public function testSave($addressId, $isDefaultBilling, $isDefaultShipping)
 {
     /** @var $customer \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject */
     $customer = $this->getMock('Magento\\Customer\\Model\\Customer', ['__wakeup', 'setDefaultBilling', 'setDefaultShipping', 'save', 'load'], [], '', false);
     $customer->expects($this->any())->method('load')->willReturnSelf();
     $this->customerFactory->expects($this->any())->method('create')->willReturn($customer);
     /** @var $address \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject */
     $address = $this->getMock('Magento\\Customer\\Model\\Address', ['__wakeup', 'getId', 'getEntityTypeId', 'getIsDefaultBilling', 'getIsDefaultShipping', 'hasDataChanges', 'validateBeforeSave', 'beforeSave', 'afterSave', 'isSaveAllowed'], [], '', false);
     $address->expects($this->once())->method('hasDataChanges')->willReturn(true);
     $address->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $address->expects($this->once())->method('validateBeforeSave');
     $address->expects($this->once())->method('beforeSave');
     $address->expects($this->once())->method('afterSave');
     $address->expects($this->any())->method('getEntityTypeId')->willReturn('3');
     $address->expects($this->any())->method('getId')->willReturn($addressId);
     $address->expects($this->any())->method('getIsDefaultShipping')->willReturn($isDefaultShipping);
     $address->expects($this->any())->method('getIsDefaultBilling')->willReturn($isDefaultBilling);
     if ($addressId && ($isDefaultBilling || $isDefaultShipping)) {
         if ($isDefaultBilling) {
             $customer->expects($this->once())->method('setDefaultBilling')->with($addressId);
         }
         if ($isDefaultShipping) {
             $customer->expects($this->once())->method('setDefaultShipping')->with($addressId);
         }
         $customer->expects($this->once())->method('save');
     } else {
         $customer->expects($this->never())->method('setDefaultBilling');
         $customer->expects($this->never())->method('setDefaultShipping');
         $customer->expects($this->never())->method('save');
     }
     $this->addressResource->setType('customer_address');
     $this->addressResource->save($address);
 }
开发者ID:opexsw,项目名称:magento2,代码行数:40,代码来源:AddressTest.php

示例2: setUp

 /**
  * SetUp
  */
 protected function setUp()
 {
     $this->layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->sessionMock = $this->getMock('Magento\\Framework\\Session\\Generic', ['clearStorage', 'setData', 'getData'], [], '', false);
     $this->customerSessionMock = $this->getMock('Magento\\Customer\\Model\\Session', ['getCustomerGroupId', 'setCustomerGroupId', 'clearStorage', 'setCustomer'], [], '', false);
     $this->customerFactoryMock = $this->getMock('Magento\\Customer\\Model\\CustomerFactory', ['create'], [], '', false);
     $this->customerMock = $this->getMock('Magento\\Customer\\Model\\Customer', ['setGroupId', '__wakeup'], [], '', false);
     $this->visitorMock = $this->getMock('Magento\\Customer\\Model\\Visitor', [], [], '', false);
     $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->customerMock));
     $this->depersonalizeCheckerMock = $this->getMock('Magento\\PageCache\\Model\\DepersonalizeChecker', [], [], '', false);
     $this->plugin = new \Magento\Customer\Model\Layout\DepersonalizePlugin($this->depersonalizeCheckerMock, $this->sessionMock, $this->customerSessionMock, $this->customerFactoryMock, $this->visitorMock);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:DepersonalizePluginTest.php

示例3: testProcessNonceException

 /**
  * @param string $params
  * @dataProvider dataProcessNonce
  */
 public function testProcessNonceException($params = null, $exceptionMessage = null)
 {
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($params['customerId']);
     $countryCollectionMock = $this->getMockBuilder('\\Magento\\Directory\\Model\\Resource\\Country\\Collection')->disableOriginalConstructor()->getMock();
     $countryCollectionMock->expects($this->any())->method('addCountryCodeFilter')->willReturn($countryCollectionMock);
     $this->countryFactoryMock->expects($this->any())->method('create')->willReturn($countryCollectionMock);
     $this->configMock->expects($this->any())->method('canUseForCountry')->willReturn($params['canUseForCountry']);
     $this->configMock->expects($this->any())->method('canUseCcTypeForCountry')->willReturn($params['canUseCcTypeForCountry']);
     $this->helperMock->expects($this->any())->method('generateCustomerId')->willReturn($params['customerId']);
     $this->customerMock->expects($this->any())->method('load')->willReturn($this->customerMock);
     $this->customerFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock);
     if (is_object($params['paymentMethodObj'])) {
         if (!$params['optionsArray']['update']) {
             $this->braintreePaymentMethodMock->expects($this->once())->method('create')->willReturn($params['paymentMethodObj']);
         } else {
             $this->braintreePaymentMethodMock->expects($this->once())->method('update')->willReturn($params['paymentMethodObj']);
         }
         if (!$params['paymentMethodObj']->success) {
             $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->willReturn(new \Magento\Framework\Phrase($exceptionMessage));
         } else {
             $this->errorHelperMock->expects($this->never())->method('parseBraintreeError');
         }
     }
     try {
         $this->model->processNonce($params['nonce'], $params['optionsArray'], $params['billingAddress']);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->assertEquals($exceptionMessage, $e->getMessage());
     }
 }
开发者ID:nja78,项目名称:magento2,代码行数:33,代码来源:VaultTest.php

示例4: prepareLoginDataMock

 /**
  * @param $customerId
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function prepareLoginDataMock($customerId)
 {
     $customerDataMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $customerDataMock->expects($this->once())->method('getId')->will($this->returnValue($customerId));
     $customerMock = $this->getMock('Magento\\Customer\\Model\\Customer', [], [], '', false);
     $customerMock->expects($this->once())->method('getId')->will($this->returnValue($customerId));
     $customerMock->expects($this->once())->method('isConfirmationRequired')->will($this->returnValue(true));
     $customerMock->expects($this->never())->method('getConfirmation')->will($this->returnValue($customerId));
     $this->customerFactoryMock->expects($this->once())->method('create')->will($this->returnValue($customerMock));
     $customerMock->expects($this->once())->method('updateData')->with($customerDataMock)->will($this->returnSelf());
     $this->_httpContextMock->expects($this->exactly(3))->method('setValue');
     return $customerDataMock;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:SessionTest.php

示例5: testAuthenticate

 /**
  * @return void
  */
 public function testAuthenticate()
 {
     $username = 'login';
     $password = '1234567';
     $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customerModel = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock();
     $customerModel->expects($this->once())->method('updateData')->willReturn($customerModel);
     $this->customerRepository->expects($this->once())->method('get')->with($username)->willReturn($customerData);
     $this->accountManagementHelper->expects($this->once())->method('checkIfLocked')->with($customerData);
     $this->accountManagementHelper->expects($this->once())->method('validatePasswordAndLockStatus')->with($customerData, $password);
     $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel);
     $this->manager->expects($this->exactly(2))->method('dispatch')->withConsecutive(['customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]], ['customer_data_object_login', ['customer' => $customerData]]);
     $this->assertEquals($customerData, $this->accountManagement->authenticate($username, $password));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:17,代码来源:AccountManagementTest.php

示例6: testRemoveByEmail

 public function testRemoveByEmail()
 {
     $this->customer->expects($this->exactly(2))->method('loadByEmail')->with(self::CUSTOMER_EMAIL)->will($this->returnValue($this->customer));
     $this->customer->expects($this->any())->method('getId')->will($this->returnValue(self::CUSTOMER_ID));
     $this->customer->expects($this->any())->method('getEmail')->will($this->returnValue(self::CUSTOMER_EMAIL));
     $this->customer->expects($this->any())->method('getWebsiteId')->will($this->returnValue(self::WEBSITE_ID));
     $this->customer->expects($this->any())->method('setEmail')->will($this->returnValue($this->customer));
     $this->customer->expects($this->any())->method('setWebsiteId')->will($this->returnValue($this->customer));
     $this->customerFactory->expects($this->exactly(2))->method('create')->will($this->returnValue($this->customer));
     $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $this->assertEquals($this->customer, $actual);
     $this->customerRegistry->removeByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $this->assertEquals($this->customer, $actual);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:CustomerRegistryTest.php

示例7: testGetList

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetList()
 {
     $sortOrder = $this->getMock('Magento\\Framework\\Api\\SortOrder', [], [], '', false);
     $filterGroup = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $filter = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
     $collection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection', [], [], '', false);
     $searchResults = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressSearchResultsInterface', [], '', false);
     $searchCriteria = $this->getMockForAbstractClass('Magento\\Framework\\Api\\SearchCriteriaInterface', [], '', false);
     $customerModel = $this->getMock('Magento\\Customer\\Model\\Customer', ['getId', 'setId', 'setStoreId', 'getStoreId', 'getAttributeSetId', 'setAttributeSetId', 'setRpToken', 'setRpTokenCreatedAt', 'getDataModel', 'setPasswordHash', 'getCollection'], [], 'customerModel', false);
     $metadata = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface', [], '', false);
     $this->searchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults);
     $searchResults->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
     $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel);
     $customerModel->expects($this->once())->method('getCollection')->willReturn($collection);
     $this->extensionAttributesJoinProcessor->expects($this->once())->method('process')->with($collection, 'Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([$metadata]);
     $metadata->expects($this->once())->method('getAttributeCode')->willReturn('attribute-code');
     $collection->expects($this->once())->method('addAttributeToSelect')->with('attribute-code');
     $collection->expects($this->once())->method('addNameToSelect');
     $collection->expects($this->at(2))->method('joinAttribute')->with('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(3))->method('joinAttribute')->with('billing_city', 'customer_address/city', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(4))->method('joinAttribute')->with('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(5))->method('joinAttribute')->with('billing_region', 'customer_address/region', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(6))->method('joinAttribute')->with('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(7))->method('joinAttribute')->with('company', 'customer_address/company', 'default_billing', null, 'left')->willReturnSelf();
     $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $collection->expects($this->once())->method('addFieldToFilter')->with([['attribute' => 'Field', 'eq' => 'Value']], []);
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
     $filter->expects($this->once())->method('getConditionType')->willReturn(false);
     $filter->expects($this->once())->method('getField')->willReturn('Field');
     $filter->expects($this->atLeastOnce())->method('getValue')->willReturn('Value');
     $collection->expects($this->once())->method('addOrder')->with('Field', 'ASC');
     $searchCriteria->expects($this->atLeastOnce())->method('getSortOrders')->willReturn([$sortOrder]);
     $sortOrder->expects($this->once())->method('getField')->willReturn('Field');
     $sortOrder->expects($this->once())->method('getDirection')->willReturn(\Magento\Framework\Api\SortOrder::SORT_ASC);
     $searchCriteria->expects($this->once())->method('getCurrentPage')->willReturn(1);
     $collection->expects($this->once())->method('setCurPage')->with(1);
     $searchCriteria->expects($this->once())->method('getPageSize')->willReturn(10);
     $collection->expects($this->once())->method('setPageSize')->with(10);
     $collection->expects($this->once())->method('getSize')->willReturn(23);
     $searchResults->expects($this->once())->method('setTotalCount')->with(23);
     $collection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$customerModel]));
     $customerModel->expects($this->atLeastOnce())->method('getDataModel')->willReturn($this->customer);
     $searchResults->expects($this->once())->method('setItems')->with([$this->customer]);
     $this->assertSame($searchResults, $this->model->getList($searchCriteria));
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:49,代码来源:CustomerRepositoryTest.php

示例8: testAuthenticate

 /**
  * @return void
  */
 public function testAuthenticate()
 {
     $username = 'login';
     $password = '1234567';
     $passwordHash = '1a2b3f4c';
     $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customerModel = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock();
     $customerModel->expects($this->once())->method('updateData')->willReturn($customerModel);
     $this->customerRepository->expects($this->once())->method('get')->with($username)->willReturn($customerData);
     $this->authenticationMock->expects($this->once())->method('authenticate');
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['getPasswordHash'])->disableOriginalConstructor()->getMock();
     $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($passwordHash);
     $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->willReturn($customerSecure);
     $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel);
     $this->manager->expects($this->exactly(2))->method('dispatch')->withConsecutive(['customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]], ['customer_data_object_login', ['customer' => $customerData]]);
     $this->assertEquals($customerData, $this->accountManagement->authenticate($username, $password));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:20,代码来源:AccountManagementTest.php


注:本文中的Magento\Customer\Model\CustomerFactory::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。