本文整理汇总了PHP中Magento\Directory\Model\CurrencyFactory::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP CurrencyFactory::expects方法的具体用法?PHP CurrencyFactory::expects怎么用?PHP CurrencyFactory::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Directory\Model\CurrencyFactory
的用法示例。
在下文中一共展示了CurrencyFactory::expects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFetchRates
public function testFetchRates()
{
$currencyFromList = ['USD'];
$currencyToList = ['EUR', 'UAH'];
$responseBody = '{"base":"USD","date":"2015-10-07","rates":{"EUR":0.9022}}';
$expectedCurrencyRateList = ['USD' => ['EUR' => 0.9022, 'UAH' => null]];
$message = "We can't retrieve a rate from http://api.fixer.io/latest?base=USD&symbols=EUR,UAH for UAH.";
/** @var \Magento\Directory\Model\Currency|\PHPUnit_Framework_MockObject_MockObject $currencyMock */
$currencyMock = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->disableOriginalConstructor()->setMethods([])->getMock();
/** @var \Magento\Framework\HTTP\ZendClient|\PHPUnit_Framework_MockObject_MockObject $currencyMock */
$httpClientMock = $this->getMockBuilder('Magento\\Framework\\HTTP\\ZendClient')->disableOriginalConstructor()->setMethods([])->getMock();
/** @var \Zend_Http_Response|\PHPUnit_Framework_MockObject_MockObject $currencyMock */
$httpResponseMock = $this->getMockBuilder('Zend_Http_Response')->disableOriginalConstructor()->setMethods([])->getMock();
$this->currencyFactoryMock->expects($this->any())->method('create')->willReturn($currencyMock);
$currencyMock->expects($this->once())->method('getConfigBaseCurrencies')->willReturn($currencyFromList);
$currencyMock->expects($this->once())->method('getConfigAllowCurrencies')->willReturn($currencyToList);
$this->httpClientFactoryMock->expects($this->any())->method('create')->willReturn($httpClientMock);
$httpClientMock->expects($this->atLeastOnce())->method('setUri')->willReturnSelf();
$httpClientMock->expects($this->atLeastOnce())->method('setConfig')->willReturnSelf();
$httpClientMock->expects($this->atLeastOnce())->method('request')->willReturn($httpResponseMock);
$httpResponseMock->expects($this->any())->method('getBody')->willReturn($responseBody);
$this->assertEquals($expectedCurrencyRateList, $this->model->fetchRates());
$messages = $this->model->getMessages();
$this->assertNotEmpty($messages);
$this->assertTrue(is_array($messages));
$this->assertEquals($message, (string) $messages[0]);
}
示例2: testFetchRates
public function testFetchRates()
{
$currencyFromList = ['USD'];
$currencyToList = ['EUR', 'UAH'];
$responseBody = '{"query":{"count":7,"created":"2016-04-05T16:46:55Z","lang":"en-US","results":{"rate":' . '[{"id":"USDEUR","Name":"USD/EUR","Rate":"0.9022","Date":"4/5/2016"}]}}}';
$expectedCurrencyRateList = ['USD' => ['EUR' => 0.9022, 'UAH' => null]];
$message = "We can't retrieve a rate from http://query.yahooapis.com/v1/public/yql?format=json" . "&q=select+*+from+yahoo.finance.xchange+where+pair+in+%28%22USDEUR%22%2C%22USDUAH%22)" . "&env=store://datatables.org/alltableswithkeys for UAH.";
/** @var \Magento\Directory\Model\Currency|\PHPUnit_Framework_MockObject_MockObject $currencyMock */
$currencyMock = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->disableOriginalConstructor()->setMethods([])->getMock();
/** @var \Magento\Framework\HTTP\ZendClient|\PHPUnit_Framework_MockObject_MockObject $currencyMock */
$httpClientMock = $this->getMockBuilder('Magento\\Framework\\HTTP\\ZendClient')->disableOriginalConstructor()->setMethods([])->getMock();
/** @var \Zend_Http_Response|\PHPUnit_Framework_MockObject_MockObject $currencyMock */
$httpResponseMock = $this->getMockBuilder('Zend_Http_Response')->disableOriginalConstructor()->setMethods([])->getMock();
$this->currencyFactoryMock->expects($this->any())->method('create')->willReturn($currencyMock);
$currencyMock->expects($this->once())->method('getConfigBaseCurrencies')->willReturn($currencyFromList);
$currencyMock->expects($this->once())->method('getConfigAllowCurrencies')->willReturn($currencyToList);
$this->httpClientFactoryMock->expects($this->any())->method('create')->willReturn($httpClientMock);
$httpClientMock->expects($this->atLeastOnce())->method('setUri')->willReturnSelf();
$httpClientMock->expects($this->atLeastOnce())->method('setConfig')->willReturnSelf();
$httpClientMock->expects($this->atLeastOnce())->method('request')->willReturn($httpResponseMock);
$httpResponseMock->expects($this->any())->method('getBody')->willReturn($responseBody);
$this->assertEquals($expectedCurrencyRateList, $this->model->fetchRates());
$messages = $this->model->getMessages();
$this->assertNotEmpty($messages);
$this->assertTrue(is_array($messages));
$this->assertEquals($message, (string) $messages[0]);
}
示例3: testConvertWithCurrencyString
public function testConvertWithCurrencyString()
{
$amount = 5.6;
$currency = 'ru';
$convertedAmount = 9.300000000000001;
$currentCurrency = $this->getCurrentCurrencyMock();
$currentCurrency->expects($this->once())->method('load')->with($currency)->will($this->returnSelf());
$this->currencyFactory->expects($this->once())->method('create')->will($this->returnValue($currentCurrency));
$baseCurrency = $this->getBaseCurrencyMock($amount, $convertedAmount, $currentCurrency);
$baseCurrency->expects($this->once())->method('getRate')->with($currentCurrency)->will($this->returnValue(1.2));
$store = $this->getStoreMock($baseCurrency);
$this->assertEquals($convertedAmount, $this->priceCurrency->convert($amount, $store, $currency));
}
示例4: testScheduledUpdateCurrencyRates
public function testScheduledUpdateCurrencyRates()
{
$this->scopeConfig->expects($this->at(0))->method('getValue')->with(Observer::IMPORT_ENABLE, ScopeInterface::SCOPE_STORE)->will($this->returnValue(1));
$this->scopeConfig->expects($this->at(1))->method('getValue')->with(Observer::CRON_STRING_PATH, ScopeInterface::SCOPE_STORE)->will($this->returnValue('cron-path'));
$this->scopeConfig->expects($this->at(2))->method('getValue')->with(Observer::IMPORT_SERVICE, ScopeInterface::SCOPE_STORE)->will($this->returnValue('import-service'));
$importInterfaceMock = $this->getMockBuilder('Magento\\Directory\\Model\\Currency\\Import\\Webservicex')->disableOriginalConstructor()->setMethods(['fetchRates', 'getMessages'])->getMock();
$importInterfaceMock->expects($this->once())->method('fetchRates')->will($this->returnValue([]));
$importInterfaceMock->expects($this->once())->method('getMessages')->will($this->returnValue([]));
$this->importFactory->expects($this->once())->method('create')->with('import-service')->will($this->returnValue($importInterfaceMock));
$currencyMock = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->disableOriginalConstructor()->setMethods(['saveRates', '__wakeup', '__sleep'])->getMock();
$currencyMock->expects($this->once())->method('saveRates')->will($this->returnValue(null));
$this->currencyFactory->expects($this->once())->method('create')->will($this->returnValue($currencyMock));
$this->observer->scheduledUpdateCurrencyRates(null);
}