本文整理汇总了PHP中Magento\Quote\Model\QuoteRepository::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP QuoteRepository::expects方法的具体用法?PHP QuoteRepository::expects怎么用?PHP QuoteRepository::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\QuoteRepository
的用法示例。
在下文中一共展示了QuoteRepository::expects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSaveAddresses
public function testSaveAddresses()
{
$cartId = 100;
$additionalData = $this->getMock('\\Magento\\Quote\\Api\\Data\\AddressAdditionalDataInterface');
$billingAddressMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
$shippingAddressMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
$this->billingAddressManagement->expects($this->once())->method('assign')->with($cartId, $billingAddressMock)->willReturn(1);
$billingAddressMock->expects($this->once())->method('format')->with('html');
$this->billingAddressManagement->expects($this->once())->method('get')->with($cartId)->willReturn($billingAddressMock);
$this->shippingAddressManagement->expects($this->once())->method('assign')->with($cartId, $shippingAddressMock)->willReturn(1);
$shippingAddressMock->expects($this->once())->method('format')->with('html');
$this->shippingAddressManagement->expects($this->once())->method('get')->with($cartId)->willReturn($shippingAddressMock);
$shippingMethodMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\ShippingMethodInterface');
$this->shippingMethodManagement->expects($this->once())->method('getList')->with($cartId)->willReturn([$shippingMethodMock]);
$paymentMethodMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\PaymentMethodInterface');
$this->paymentMethodManagement->expects($this->once())->method('getList')->with($cartId)->willReturn([$paymentMethodMock]);
$addressDetailsMock = $this->getMock('\\Magento\\Quote\\Model\\AddressDetails', [], [], '', false);
$this->addressDetailsFactory->expects($this->once())->method('create')->willReturn($addressDetailsMock);
$addressDetailsMock->expects($this->once())->method('setShippingMethods')->with([$shippingMethodMock])->willReturnSelf();
$addressDetailsMock->expects($this->once())->method('setPaymentMethods')->with([$paymentMethodMock])->willReturnSelf();
$this->dataProcessor->expects($this->once())->method('process')->with($additionalData);
$quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
$quote->expects($this->once())->method('setCheckoutMethod')->willReturnSelf();
$this->quoteRepository->expects($this->once())->method('getActive')->willReturn($quote);
$this->model->saveAddresses($cartId, $billingAddressMock, $shippingAddressMock, $additionalData, 'register');
}
示例2: testSavePaymentInQuote
public function testSavePaymentInQuote()
{
$quoteId = 1;
$response = new DataObject();
$payment = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock();
$payment->expects($this->once())->method('setAdditionalInformation')->with('pnref');
$this->errorHandlerMock->expects($this->once())->method('handle')->with($payment, $response);
$quote = $this->getMock('Magento\\Quote\\Api\\Data\\CartInterface', [], [], '', false);
$quote->expects($this->exactly(2))->method('getId')->willReturn($quoteId);
$this->sessionTransparent->expects($this->once())->method('getQuoteId')->willReturn($quoteId);
$this->quoteRepository->expects($this->once())->method('get')->willReturn($quote);
$this->paymentMethodManagementInterface->expects($this->once())->method('get')->willReturn($payment);
$this->paymentMethodManagementInterface->expects($this->once())->method('set');
$this->model->savePaymentInQuote($response);
}
示例3: testGetCartForCustomer
public function testGetCartForCustomer()
{
$customerId = 100;
$cartMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false);
$this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer')->with($customerId)->willReturn($cartMock);
$this->assertEquals($cartMock, $this->model->getCartForCustomer($customerId));
}
示例4: testSaveBilling
/**
* @dataProvider saveBillingDataProvider
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function testSaveBilling($data, $customerAddressId, $quoteCustomerId, $addressCustomerId, $isAddress, $validateDataResult, $validateResult, $checkoutMethod, $customerPassword, $confirmPassword, $validationResultMessages, $isEmailAvailable, $isVirtual, $getStepDataResult, $expected)
{
$useForShipping = (int) $data['use_for_shipping'];
$passwordHash = 'password hash';
$this->requestMock->expects($this->any())->method('isAjax')->will($this->returnValue(false));
$customerValidationResultMock = $this->getMock('Magento\\Customer\\Api\\Data\\ValidationResultsInterface', [], [], '', false);
$customerValidationResultMock->expects($this->any())->method('isValid')->will($this->returnValue(empty($validationResultMessages)));
$customerValidationResultMock->expects($this->any())->method('getMessages')->will($this->returnValue($validationResultMessages));
$this->accountManagementMock->expects($this->any())->method('getPasswordHash')->with($customerPassword)->will($this->returnValue($passwordHash));
$this->accountManagementMock->expects($this->any())->method('validate')->will($this->returnValue($customerValidationResultMock));
$this->accountManagementMock->expects($this->any())->method('isEmailAvailable')->will($this->returnValue($isEmailAvailable));
/** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject $quoteMock */
$quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getData', 'getCustomerId', '__wakeup', 'getBillingAddress', 'setPasswordHash', 'getCheckoutMethod', 'isVirtual', 'getShippingAddress', 'getCustomerData', 'collectTotals', 'save', 'getCustomer'], [], '', false);
$customerMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\AbstractExtensibleObject', [], '', false, true, true, ['__toArray']);
$shippingAddressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['setSameAsBilling', 'save', 'collectTotals', 'addData', 'setShippingMethod', 'setCollectShippingRates', '__wakeup'], [], '', false);
$quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock));
$shippingAddressMock->expects($useForShipping ? $this->any() : $this->once())->method('setSameAsBilling')->with($useForShipping)->will($this->returnSelf());
$expects = !$useForShipping || $checkoutMethod != Onepage::METHOD_REGISTER ? $this->once() : $this->never();
$shippingAddressMock->expects($expects)->method('save');
$shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('addData')->will($this->returnSelf());
$shippingAddressMock->expects($this->any())->method('setSaveInAddressBook')->will($this->returnSelf());
$shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('setShippingMethod')->will($this->returnSelf());
$shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('setCollectShippingRates')->will($this->returnSelf());
$shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('collectTotals');
$quoteMock->expects($this->any())->method('setPasswordHash')->with($passwordHash);
$quoteMock->expects($this->any())->method('getCheckoutMethod')->will($this->returnValue($checkoutMethod));
$quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue($isVirtual));
$addressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['setSaveInAddressBook', 'getData', 'setEmail', '__wakeup', 'importCustomerAddressData', 'validate', 'save'], [], '', false);
$addressMock->expects($this->any())->method('importCustomerAddressData')->will($this->returnSelf());
$addressMock->expects($this->atLeastOnce())->method('validate')->will($this->returnValue($validateResult));
$addressMock->expects($this->any())->method('getData')->will($this->returnValue([]));
$quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock));
$quoteMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($quoteCustomerId));
$this->quoteRepositoryMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->once() : $this->never())->method('save')->with($quoteMock);
$addressMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())->method('save');
$quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock));
$data1 = [];
$extensibleDataObjectConverterMock = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', ['toFlatArray'], [], '', false);
$extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->with($customerMock)->will($this->returnValue($data1));
$formMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
$formMock->expects($this->atLeastOnce())->method('validateData')->will($this->returnValue($validateDataResult));
$this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock));
$formMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->requestMock));
$formMock->expects($this->any())->method('extractData')->with($this->requestMock)->will($this->returnValue([]));
$formMock->expects($this->any())->method('validateData')->with([])->will($this->returnValue(false));
$customerDataMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
$this->customerDataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerDataMock));
$this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
$this->checkoutSessionMock->expects($this->any())->method('getStepData')->will($this->returnValue($useForShipping ? true : $getStepDataResult));
$this->checkoutSessionMock->expects($this->any())->method('setStepData')->will($this->returnSelf());
$customerAddressMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
$customerAddressMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($addressCustomerId));
$this->addressRepositoryMock->expects($this->any())->method('getById')->will($isAddress ? $this->returnValue($customerAddressMock) : $this->throwException(new \Exception()));
$websiteMock = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
$this->storeManagerMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock));
$this->assertEquals($expected, $this->onepage->saveBilling($data, $customerAddressId));
}
示例5: testInitializeQuoteForReview
/**
* @dataProvider initializeQuoteForReviewDataProvider
*/
public function testInitializeQuoteForReview($paymentMethodNonce, $details, $expectedShipping, $expectedBilling, $expectedPaymentAdditionalInfo)
{
$this->verifyIgnoreAddressValidation();
$this->quoteMock->expects($this->any())->method('getIsVirtual')->willReturn(false);
$paymentMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock();
$paymentMock->expects($this->once())->method('setMethod')->with(PayPal::METHOD_CODE);
$this->quoteMock->expects($this->any())->method('getPayment')->willReturn($paymentMock);
foreach ($expectedShipping as $methodName => $value) {
$this->shippingAddressMock->expects($this->once())->method($methodName)->with($value)->willReturnSelf();
}
foreach ($expectedBilling as $methodName => $value) {
$this->billingAddressMock->expects($this->once())->method($methodName)->with($value)->willReturnSelf();
}
$index = 1;
foreach ($expectedPaymentAdditionalInfo as $key => $value) {
$paymentMock->expects($this->at($index))->method('setAdditionalInformation')->with($key, $value);
$index++;
}
$this->quoteMock->expects($this->once())->method('collectTotals');
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
$this->model->initializeQuoteForReview($paymentMethodNonce, $details);
}
示例6: testEstimateByExtendedAddress
/**
* @covers \Magento\Quote\Model\ShippingMethodManagement::estimateByExtendedAddress
*/
public function testEstimateByExtendedAddress()
{
$cartId = 1;
$addressData = ['region' => 'California', 'region_id' => 23, 'country_id' => 1, 'postcode' => 90200];
$currencyCode = 'UAH';
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->setMethods(['getData'])->getMock();
$this->quoteRepository->expects(static::once())->method('getActive')->with($cartId)->willReturn($this->quote);
$this->quote->expects(static::once())->method('isVirtual')->willReturn(false);
$this->quote->expects(static::once())->method('getItemsCount')->willReturn(1);
$address->expects(static::once())->method('getData')->willReturn($addressData);
$this->quote->expects(static::once())->method('getShippingAddress')->willReturn($this->shippingAddress);
$this->shippingAddress->expects(static::once())->method('addData')->with($addressData)->willReturnSelf();
$this->shippingAddress->expects(static::once())->method('setCollectShippingRates')->with(true)->willReturnSelf();
$this->totalsCollector->expects(static::once())->method('collectAddressTotals')->with($this->quote, $this->shippingAddress)->willReturnSelf();
$rate = $this->getMockBuilder(Rate::class)->disableOriginalConstructor()->setMethods([])->getMock();
$methodObject = $this->getMockForAbstractClass(ShippingMethodInterface::class);
$expectedRates = [$methodObject];
$this->shippingAddress->expects(static::once())->method('getGroupedAllShippingRates')->willReturn([[$rate]]);
$this->quote->expects(static::once())->method('getQuoteCurrencyCode')->willReturn($currencyCode);
$this->converter->expects(static::once())->method('modelToDataObject')->with($rate, $currencyCode)->willReturn($methodObject);
$carriersRates = $this->model->estimateByExtendedAddress($cartId, $address);
static::assertEquals($expectedRates, $carriersRates);
}