本文整理汇总了PHP中Magento\Framework\Pricing\PriceCurrencyInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP PriceCurrencyInterface::expects方法的具体用法?PHP PriceCurrencyInterface::expects怎么用?PHP PriceCurrencyInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Pricing\PriceCurrencyInterface
的用法示例。
在下文中一共展示了PriceCurrencyInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCurrencyByStore
/**
* @param string $amount
* @param string $store
* @param bool $format
* @param bool $includeContainer
* @param string $result
* @dataProvider currencyByStoreDataProvider
*/
public function testCurrencyByStore($amount, $store, $format, $includeContainer, $result)
{
if ($format) {
$this->priceCurrencyMock->expects($this->once())->method('convertAndFormat')->with($amount, $includeContainer, PriceCurrencyInterface::DEFAULT_PRECISION, $store)->will($this->returnValue($result));
} else {
$this->priceCurrencyMock->expects($this->once())->method('convert')->with($amount, $store)->will($this->returnValue($result));
}
$helper = $this->getHelper(['priceCurrency' => $this->priceCurrencyMock]);
$this->assertEquals($result, $helper->currencyByStore($amount, $store, $format, $includeContainer));
}
示例2: testGetCustomAmount
public function testGetCustomAmount()
{
$exclude = false;
$amount = 21.0;
$convertedValue = 30.25;
$customAmount = 42.0;
$this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedValue));
$this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedValue, $this->saleableItemMock, $exclude)->will($this->returnValue($customAmount));
$this->assertEquals($customAmount, $this->price->getCustomAmount($amount, $exclude));
}
示例3: testGetLinkAmount
public function testGetLinkAmount()
{
$amount = 100;
$convertedAmount = 50;
$this->linkMock->expects($this->once())->method('getPrice')->will($this->returnValue($amount));
$this->linkMock->expects($this->once())->method('getProduct')->will($this->returnValue($this->saleableItemMock));
$this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedAmount));
$this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedAmount, $this->equalTo($this->saleableItemMock))->will($this->returnValue($convertedAmount));
$result = $this->linkPrice->getLinkAmount($this->linkMock);
$this->assertEquals($convertedAmount, $result);
}
示例4: testPrepareDataSource
public function testPrepareDataSource()
{
$itemName = 'itemName';
$oldItemValue = 'oldItemValue';
$newItemValue = 'newItemValue';
$dataSource = ['data' => ['items' => [[$itemName => $oldItemValue]]]];
$this->priceFormatterMock->expects($this->once())->method('format')->with($oldItemValue, false)->willReturn($newItemValue);
$this->model->setData('name', $itemName);
$dataSource = $this->model->prepareDataSource($dataSource);
$this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
}
示例5: testGetValue
/**
* @param bool $isValidInterval
* @param float $specialPrice
* @param float|bool $specialPriceValue
*
* @dataProvider specialPriceDataProvider
*/
public function testGetValue($isValidInterval, $specialPrice, $specialPriceValue)
{
$expected = 56.34;
$specialPriceModel = $this->objectManager->getObject('Magento\\Catalog\\Pricing\\Price\\SpecialPrice', ['saleableItem' => $this->prepareSaleableItem($specialPrice), 'localeDate' => $this->prepareLocaleDate($isValidInterval), 'priceCurrency' => $this->priceCurrencyMock]);
if ($isValidInterval) {
$this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($specialPriceValue)->will($this->returnValue($expected));
} else {
$expected = $specialPriceValue;
}
$this->assertSame($expected, $specialPriceModel->getValue());
}
示例6: setUp
public function setUp()
{
$objectManager = new ObjectManager($this);
$this->coreRegistry = $this->getMockBuilder('\\Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry'])->getMock();
$this->orderTaxService = $this->getMockBuilder('\\Magento\\Tax\\Service\\V1\\OrderTaxService')->disableOriginalConstructor()->setMethods(['getOrderTaxDetails'])->getMock();
$this->priceCurrency = $this->getMockBuilder('Magento\\Framework\\Pricing\\PriceCurrencyInterface')->getMock();
$this->priceCurrency->expects($this->any())->method('round')->will($this->returnCallback(function ($argument) {
return round($argument, 2);
}));
$this->taxHelper = $objectManager->getObject('Magento\\Tax\\Helper\\Data', ['coreRegistry' => $this->coreRegistry, 'orderTaxService' => $this->orderTaxService, 'priceCurrency' => $this->priceCurrency]);
$this->orderTaxDetailsBuilder = $objectManager->getObject('Magento\\Tax\\Service\\V1\\Data\\OrderTaxDetailsBuilder');
}
示例7: testGetMinimalPrice
public function testGetMinimalPrice()
{
$expectedResult = 5;
$this->saleableInterfaceMock->expects($this->once())->method('getPrice')->will($this->returnValue($expectedResult));
$this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->will($this->returnArgument(0));
$this->bundleCalculatorMock->expects($this->once())->method('getMinRegularAmount')->with($expectedResult, $this->saleableInterfaceMock)->will($this->returnValue($expectedResult));
$result = $this->regularPrice->getMinimalPrice();
$this->assertEquals($expectedResult, $result, 'Incorrect amount');
//Calling a second time, should use cached value
$result = $this->regularPrice->getMinimalPrice();
$this->assertEquals($expectedResult, $result, 'Incorrect amount the second time');
}
示例8: testGetValue
public function testGetValue()
{
$this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo('regular_price'))->will($this->returnValue($this->regularPrice));
$this->regularPrice->expects($this->once())->method('getValue')->will($this->returnValue(100));
$this->productMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(null));
$this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(3));
$this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock));
$this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue($this->attributeMock));
$this->attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($this->backendMock));
$this->backendMock->expects($this->once())->method('afterLoad')->with($this->equalTo($this->productMock))->will($this->returnValue($this->backendMock));
$this->priceCurrencyMock->expects($this->never())->method('convertAndRound');
$this->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => 3, 'website_price' => 80]]));
$this->assertEquals(20, $this->groupPrice->getValue());
$this->assertEquals(20, $this->groupPrice->getValue());
}
示例9: testIsMinimalPriceLessMsrp
public function testIsMinimalPriceLessMsrp()
{
$msrp = 120;
$convertedFinalPrice = 200;
$this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->will($this->returnCallback(function ($arg) {
return round(2 * $arg, 2);
}));
$finalPriceMock = $this->getMockBuilder('\\Magento\\Catalog\\Pricing\\Price\\FinalPrice')->disableOriginalConstructor()->getMock();
$finalPriceMock->expects($this->any())->method('getValue')->will($this->returnValue($convertedFinalPrice));
$priceInfoMock = $this->getMockBuilder('\\Magento\\Framework\\Pricing\\PriceInfo\\Base')->disableOriginalConstructor()->getMock();
$priceInfoMock->expects($this->once())->method('getPrice')->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)->will($this->returnValue($finalPriceMock));
$this->productMock->expects($this->any())->method('getMsrp')->will($this->returnValue($msrp));
$this->productMock->expects($this->any())->method('getPriceInfo')->will($this->returnValue($priceInfoMock));
$result = $this->helper->isMinimalPriceLessMsrp($this->productMock);
$this->assertTrue($result, "isMinimalPriceLessMsrp returned incorrect value");
}
示例10: testPrepareJsonAttributes
public function testPrepareJsonAttributes()
{
$options = [];
$attributeId = 1;
$attributeCode = 'test_attribute';
$attributeLabel = 'Test';
$pricingValue = 100;
$amount = 120;
$modifiedValue = 140;
$valueIndex = 2;
$optionId = 1;
$expected = ['priceOptions' => [$attributeId => ['id' => $attributeId, 'code' => $attributeCode, 'label' => $attributeLabel, 'options' => [0 => ['id' => $valueIndex, 'label' => $attributeLabel, 'price' => $modifiedValue, 'oldPrice' => $modifiedValue, 'inclTaxPrice' => $modifiedValue, 'exclTaxPrice' => $pricingValue, 'products' => []]]]], 'defaultValues' => [$attributeId => $optionId]];
$attributePrices = [['is_percent' => false, 'pricing_value' => $pricingValue, 'value_index' => $valueIndex, 'label' => $attributeLabel]];
$configurableAttributes = [$this->getAttributeMock($attributeId, $attributeCode, $attributeLabel, $attributePrices)];
$configuredValueMock = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->getMock();
$configuredValueMock->expects($this->any())->method('getData')->will($this->returnValue($optionId));
$configurableProduct = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock();
$configurableProduct->expects($this->once())->method('getConfigurableAttributes')->with($this->equalTo($this->saleableItemMock))->will($this->returnValue($configurableAttributes));
$this->saleableItemMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($configurableProduct));
$this->saleableItemMock->expects($this->any())->method('setParentId');
$this->saleableItemMock->expects($this->any())->method('hasPreconfiguredValues')->will($this->returnValue(true));
$this->saleableItemMock->expects($this->any())->method('getPreconfiguredValues')->will($this->returnValue($configuredValueMock));
$this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo($pricingValue), $this->equalTo($this->saleableItemMock))->will($this->returnValue($amount));
$this->calculatorMock->expects($this->any())->method('getAmount')->will($this->returnValue($this->getModifiedAmountMock($modifiedValue, $pricingValue)));
$storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
$this->priceCurrency->expects($this->once())->method('convert')->with($this->equalTo($modifiedValue))->will($this->returnArgument(0));
$this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
$result = $this->attribute->prepareAttributes($options);
$this->assertEquals($expected, $result);
}
示例11: testCollect
public function testCollect()
{
$this->shippingAssignment->expects($this->exactly(3))->method('getShipping')->willReturn($this->shipping);
$this->shipping->expects($this->exactly(2))->method('getAddress')->willReturn($this->address);
$this->shipping->expects($this->once())->method('getMethod')->willReturn('flatrate');
$this->shippingAssignment->expects($this->atLeastOnce())->method('getItems')->willReturn([$this->cartItem]);
$this->freeShipping->expects($this->once())->method('isFreeShipping')->with($this->quote, [$this->cartItem])->willReturn(true);
$this->address->expects($this->once())->method('setFreeShipping')->with(true);
$this->total->expects($this->atLeastOnce())->method('setTotalAmount');
$this->total->expects($this->atLeastOnce())->method('setBaseTotalAmount');
$this->cartItem->expects($this->atLeastOnce())->method('getProduct')->willReturnSelf();
$this->cartItem->expects($this->atLeastOnce())->method('isVirtual')->willReturn(false);
$this->cartItem->expects($this->once())->method('getParentItem')->willReturn(false);
$this->cartItem->expects($this->once())->method('getHasChildren')->willReturn(false);
$this->cartItem->expects($this->once())->method('getWeight')->willReturn(2);
$this->cartItem->expects($this->atLeastOnce())->method('getQty')->willReturn(2);
$this->address->expects($this->once())->method('getFreeShipping')->willReturn(true);
$this->cartItem->expects($this->once())->method('setRowWeight')->with(0);
$this->address->expects($this->once())->method('setItemQty')->with(2);
$this->address->expects($this->atLeastOnce())->method('setWeight');
$this->address->expects($this->atLeastOnce())->method('setFreeMethodWeight');
$this->address->expects($this->once())->method('collectShippingRates');
$this->address->expects($this->once())->method('getAllShippingRates')->willReturn([$this->rate]);
$this->rate->expects($this->once())->method('getCode')->willReturn('flatrate');
$this->quote->expects($this->once())->method('getStore')->willReturn($this->store);
$this->rate->expects($this->atLeastOnce())->method('getPrice')->willReturn(5);
$this->priceCurrency->expects($this->once())->method('convert')->with(5, $this->store)->willReturn(5);
$this->total->expects($this->once())->method('setShippingAmount')->with(5);
$this->rate->expects($this->once())->method('getCarrierTitle')->willReturn('Carrier title');
$this->rate->expects($this->once())->method('getMethodTitle')->willReturn('Method title');
$this->address->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title');
$this->address->expects($this->once())->method('getShippingDescription')->willReturn('Carrier title - Method title');
$this->total->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title');
$this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total);
}
示例12: testToHtml
/**
* Test for method _toHtml
*
* @return void
*/
public function testToHtml()
{
$productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getProductUrl', 'getDescription', 'getAllowedPriceInRss', 'getName', '__wakeup', 'getResourceCollection'], [], '', false);
$productCollectionMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory', ['addPriceDataFieldFilter', 'addPriceData', 'addAttributeToSelect', 'addAttributeToSort', 'getSelect'], [], '', false);
$rssObjMock = $this->getMock('Magento\\Rss\\Model\\Rss', [], [], '', false);
$productUrl = '<a href="http://product.url">Product Url</a>';
$imgThumbSrc = 'http://source-for-thumbnail';
$productTitle = 'Product title';
$basePriceFormatted = '<span class="price">$10.00</span>';
$finalPriceFormatted = '<span class="price">$20.00</span>';
$productDescription = '<table><tr>' . '<td><a href="' . $productUrl . '"><img src="' . $imgThumbSrc . '" alt="" border="0" align="left" height="75" width="75" /></a></td>' . '<td style="text-decoration:none;"><p>Price: ' . $basePriceFormatted . ' Special Price: ' . $finalPriceFormatted . '</p></td></tr></table>';
$expectedData = ['title' => $productTitle, 'link' => $productUrl, 'description' => $productDescription];
$expectedResult = new \Magento\Framework\Object(['rss_feed' => '<xml>Feed of the rss</xml>']);
$this->addMocks();
$this->productFactoryMock->expects($this->once())->method('create')->will($this->returnValue($productMock));
$productMock->expects($this->once())->method('getResourceCollection')->will($this->returnValue($productCollectionMock));
$productCollectionMock->expects($this->once())->method('addPriceDataFieldFilter')->will($this->returnSelf());
$productCollectionMock->expects($this->once())->method('addPriceData')->will($this->returnSelf());
$productCollectionMock->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf());
$productCollectionMock->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf());
$this->rssFactoryMock->expects($this->once())->method('create')->will($this->returnValue($rssObjMock));
$productMock->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue($productUrl));
$this->imageHelperMock->expects($this->once())->method('resize')->will($this->returnValue($imgThumbSrc));
$productMock->expects($this->any())->method('getAllowedPriceInRss')->will($this->returnValue(true));
$productMock->expects($this->once())->method('getName')->will($this->returnValue($productTitle));
$this->priceCurrencyMock->expects($this->exactly(2))->method('convertAndFormat')->will($this->returnValueMap([[10, true, PriceCurrencyInterface::DEFAULT_PRECISION, null, null, $basePriceFormatted], [20, true, PriceCurrencyInterface::DEFAULT_PRECISION, null, null, $finalPriceFormatted]]));
$rssObjMock->expects($this->once())->method('_addEntry')->with($expectedData)->will($this->returnSelf());
$rssObjMock->expects($this->once())->method('createRssXml')->will($this->returnValue($expectedResult));
$this->assertEquals($expectedResult, $this->block->toHtml());
}
示例13: testGetOptionValueModifiedIsNotPercent
/**
* test method testGetOptionValueModified with option is_percent = false
*/
public function testGetOptionValueModifiedIsNotPercent()
{
$this->saleableItemMock->expects($this->once())->method('setParentId')->with($this->equalTo(true))->will($this->returnValue($this->returnSelf()));
$this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo(77.33), $this->equalTo($this->saleableItemMock))->will($this->returnValue(77.67));
$this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo(77.67), $this->equalTo($this->saleableItemMock), null, [\Magento\Catalog\Pricing\Price\CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true])->will($this->returnValue(80.98999999999999));
$this->priceCurrency->expects($this->once())->method('convertAndRound')->will($this->returnArgument(0));
$this->assertEquals(80.98999999999999, $this->attribute->getOptionValueModified(['is_percent' => false, 'pricing_value' => 77.33]));
}
示例14: testCalculate
/**
* @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate
*/
public function testCalculate()
{
$this->rule->setData(['id' => 1, 'discount_amount' => 10.0]);
$this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue([]));
$store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
$this->priceCurrency->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0));
$this->priceCurrency->expects($this->atLeastOnce())->method('round')->will($this->returnArgument(0));
$this->quote->expects($this->any())->method('getStore')->will($this->returnValue($store));
/** validators data */
$this->validator->expects($this->once())->method('getItemPrice')->with($this->item)->will($this->returnValue(100));
$this->validator->expects($this->once())->method('getItemBasePrice')->with($this->item)->will($this->returnValue(100));
$this->validator->expects($this->once())->method('getItemOriginalPrice')->with($this->item)->will($this->returnValue(100));
$this->validator->expects($this->once())->method('getItemBaseOriginalPrice')->with($this->item)->will($this->returnValue(100));
$this->address->expects($this->once())->method('setCartFixedRules')->with([1 => 0.0]);
$this->model->calculate($this->rule, $this->item, 1);
$this->assertEquals($this->data->getAmount(), 10);
$this->assertEquals($this->data->getBaseAmount(), 10);
$this->assertEquals($this->data->getOriginalAmount(), 10);
$this->assertEquals($this->data->getBaseOriginalAmount(), 100);
}
示例15: testFormatPriceQuoteItem
public function testFormatPriceQuoteItem()
{
$price = 3.554;
$formattedPrice = "\$3.55";
$storeMock = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['formatPrice', '__wakeup'])->getMock();
$this->priceCurrency->expects($this->once())->method('format')->with($price, true)->will($this->returnValue($formattedPrice));
$itemMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['getStore', '__wakeup'])->getMock();
$itemMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
$this->renderer->setItem($itemMock);
$this->assertEquals($formattedPrice, $this->renderer->formatPrice($price));
}