/** * @covers ::load */ public function testLoad() { $currency_code_from = 'EUR'; $currency_code_to = 'NLG'; $rate = new ExchangeRate($currency_code_from, $currency_code_to, '2.20371'); $exchange_rate_provider_id_a = $this->randomMachineName(); $exchange_rate_provider_id_b = $this->randomMachineName(); $exchange_rate_provider_b = $this->getMock('\\Commercie\\CurrencyExchange\\ExchangeRateProviderInterface'); $exchange_rate_provider_b->expects($this->once())->method('load')->with($currency_code_from, $currency_code_to)->willReturn($rate); $plugin_definitions = [$exchange_rate_provider_id_a => ['id' => $exchange_rate_provider_id_a], $exchange_rate_provider_id_b => ['id' => $exchange_rate_provider_id_b]]; $this->currencyExchangeRateProviderManager->expects($this->once())->method('createInstance')->with($exchange_rate_provider_id_b)->willReturn($exchange_rate_provider_b); $this->currencyExchangeRateProviderManager->expects($this->once())->method('getDefinitions')->willReturn($plugin_definitions); $config_value = [['plugin_id' => $exchange_rate_provider_id_a, 'status' => FALSE], ['plugin_id' => $exchange_rate_provider_id_b, 'status' => TRUE]]; $config = $this->getMockBuilder('\\Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock(); $config->expects($this->once())->method('get')->with('plugins')->will($this->returnValue($config_value)); $this->configFactory->expects($this->once())->method('get')->with('currency.exchange_rate_provider')->will($this->returnValue($config)); $this->assertSame($rate, $this->sut->load($currency_code_from, $currency_code_to)); }