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); }
public function testScheduledUpdateCurrencyRates() { //skipping test if service is unavailable $url = str_replace('{{CURRENCY_FROM}}', 'USD', \Magento\Directory\Model\Currency\Import\Webservicex::CURRENCY_CONVERTER_URL); $url = str_replace('{{CURRENCY_TO}}', 'GBP', $url); try { file_get_contents($url); } catch (\PHPUnit_Framework_Error_Warning $e) { $this->markTestSkipped('http://www.webservicex.net is unavailable '); } $allowedCurrencies = 'USD,GBP,EUR'; $this->configResource->saveConfig($this->allowedCurrenciesPath, $allowedCurrencies, ScopeInterface::SCOPE_STORE, 0); $this->observer->scheduledUpdateCurrencyRates(null); /** @var Currency $currencyResource */ $currencyResource = $this->objectManager->create('Magento\\Directory\\Model\\CurrencyFactory')->create()->getResource(); $rates = $currencyResource->getCurrencyRates($this->baseCurrency, explode(',', $allowedCurrencies)); $this->assertNotEmpty($rates); }