/** * {@inheritdoc} */ public function loadMultiple(array $currency_codes) { $exchange_rates = []; foreach ($this->exchangeRateProvider->loadMultiple($currency_codes) as $source_currency_code => $destinations) { foreach ($destinations as $destination_currency_code => $exchange_rate) { $exchange_rates[$source_currency_code][$destination_currency_code] = ExchangeRate::createFromExchangeRate($exchange_rate, $this->getPluginId()); } } return $exchange_rates; }
public function loadMultiple(array $currencyCodes) { $exchangeRates = $this->decoratedExchangeRateProvider->loadMultiple($currencyCodes); foreach ($exchangeRates as $sourceCurrencyCode => $exchangeRatePerSourceCurrency) { foreach ($exchangeRatePerSourceCurrency as $destinationCurrencyCode => $exchangeRate) { $exchangeRates[$sourceCurrencyCode][$destinationCurrencyCode] = call_user_func($this->processCallback, $exchangeRate); } } return $exchangeRates; }
/** * @covers ::loadMultiple */ public function testLoadMultiple() { $source_currency_code = $this->randomMachineName(); $destination_currency_code_a = $this->randomMachineName(); $destination_currency_code_b = $this->randomMachineName(); $exchange_rate_a = new ExchangeRate($source_currency_code, $destination_currency_code_a, mt_rand(), $this->pluginId); $exchange_rate_b = new ExchangeRate($source_currency_code, $destination_currency_code_b, mt_rand(), $this->pluginId); $exchange_rates = [$source_currency_code => [$destination_currency_code_a => $exchange_rate_a, $destination_currency_code_b => $exchange_rate_b]]; $this->exchangeRateProvider->expects($this->once())->method('loadMultiple')->with([$source_currency_code => [$destination_currency_code_a, $destination_currency_code_b]])->willReturn($exchange_rates); $loaded_exchange_rates = $this->sut->loadMultiple([$source_currency_code => [$destination_currency_code_a, $destination_currency_code_b]]); $this->assertExchangeRateEquals($exchange_rate_a, $loaded_exchange_rates[$source_currency_code][$destination_currency_code_a]); $this->assertExchangeRateEquals($exchange_rate_b, $loaded_exchange_rates[$source_currency_code][$destination_currency_code_b]); }
/** * @covers ::loadMultiple */ public function testLoadMultiple() { $sourceCurrencyCode = 'nlg'; $destinationCurrencyCode = 'EUR'; $nonExistentCurrencyCode = 'foo'; $sourceToDestinationRate = '2.20371'; $destinationToSourceRate = '0,45378021609014'; $sourceToDestinationDecoratedExchangeRate = new ExchangeRate($sourceCurrencyCode, $destinationCurrencyCode, $sourceToDestinationRate); $destinationToSourceDecoratedExchangeRate = new ExchangeRate($destinationCurrencyCode, $sourceCurrencyCode, $destinationToSourceRate); $sourceIdenticalDecoratedExchangeRate = new ExchangeRate($sourceCurrencyCode, $sourceCurrencyCode, 1); $destinationIdenticalDecoratedExchangeRate = new ExchangeRate($destinationCurrencyCode, $destinationCurrencyCode, 1); $currencyCodes = [$sourceCurrencyCode => [$sourceCurrencyCode, $destinationCurrencyCode, $nonExistentCurrencyCode], $destinationCurrencyCode => [$sourceCurrencyCode, $destinationCurrencyCode, $nonExistentCurrencyCode]]; $decoratedExchangeRates = [$sourceCurrencyCode => [$sourceCurrencyCode => $sourceIdenticalDecoratedExchangeRate, $destinationCurrencyCode => $sourceToDestinationDecoratedExchangeRate, $nonExistentCurrencyCode => null], $destinationCurrencyCode => [$sourceCurrencyCode => $destinationToSourceDecoratedExchangeRate, $destinationCurrencyCode => $destinationIdenticalDecoratedExchangeRate, $nonExistentCurrencyCode => null], $nonExistentCurrencyCode => [$sourceCurrencyCode => null, $destinationCurrencyCode => null, $nonExistentCurrencyCode => null]]; $this->decoratedExchangeRateProvider->expects($this->once())->method('loadMultiple')->with($currencyCodes)->willReturn($decoratedExchangeRates); $retrievedExchangeRates = $this->sut->loadMultiple($currencyCodes); // Ensure that these are the exchange rates that were returned by the // decorated provider. $this->assertSame($decoratedExchangeRates, $retrievedExchangeRates); // Ensure the process callback was executed for all exchange rates. $this->assertTrue($retrievedExchangeRates[$sourceCurrencyCode][$sourceCurrencyCode]->processed); $this->assertTrue($retrievedExchangeRates[$sourceCurrencyCode][$destinationCurrencyCode]->processed); $this->assertTrue($retrievedExchangeRates[$destinationCurrencyCode][$sourceCurrencyCode]->processed); $this->assertTrue($retrievedExchangeRates[$destinationCurrencyCode][$destinationCurrencyCode]->processed); }