public function setUp()
 {
     $currencies = [];
     $currencies['RUB'] = $this->getMock('\\RedCode\\Currency\\ICurrency');
     $currencies['RUB']->method('getCode')->willReturn('RUB');
     $currencies['EUR'] = $this->getMock('\\RedCode\\Currency\\ICurrency');
     $currencies['EUR']->method('getCode')->willReturn('EUR');
     $currencies['USD'] = $this->getMock('\\RedCode\\Currency\\ICurrency');
     $currencies['USD']->method('getCode')->willReturn('USD');
     $this->currencyRateManager = $this->getMock('\\RedCode\\Currency\\Rate\\ICurrencyRateManager');
     $this->currencyRateManager->method('getNewInstance')->will($this->returnCallback(function (ICurrency $currency, ICurrencyRateProvider $provider, \DateTime $date, $rateValue, $nominal) {
         $rate = $this->getMock('\\RedCode\\Currency\\Rate\\ICurrencyRate');
         $rate->method('getDate')->willReturn($date);
         $rate->method('getRate')->willReturn($rateValue);
         $rate->method('getNominal')->willReturn($nominal);
         $rate->method('getProviderName')->willReturn($provider->getName());
         $rate->method('getCurrency')->willReturn($currency);
         return $rate;
     }));
     $this->currencyManager = $this->getMock('\\RedCode\\Currency\\ICurrencyManager');
     $this->currencyManager->method('getCurrency')->will($this->returnCallback(function ($name) use($currencies) {
         $name = strtoupper($name);
         if (isset($currencies[$name])) {
             return $currencies[$name];
         }
         return null;
     }));
     $this->currencyManager->method('getAll')->will($this->returnCallback(function () use($currencies) {
         return array_values($currencies);
     }));
 }
 public function setUp()
 {
     $currencies = [];
     $currencies['RUB'] = $this->getMock('\\RedCode\\Currency\\ICurrency');
     $currencies['RUB']->method('getCode')->willReturn('RUB');
     $currencies['EUR'] = $this->getMock('\\RedCode\\Currency\\ICurrency');
     $currencies['EUR']->method('getCode')->willReturn('EUR');
     $currencies['USD'] = $this->getMock('\\RedCode\\Currency\\ICurrency');
     $currencies['USD']->method('getCode')->willReturn('USD');
     $currencies['GBP'] = $this->getMock('\\RedCode\\Currency\\ICurrency');
     $currencies['GBP']->method('getCode')->willReturn('GBP');
     $inversedProvider = $this->getMock('\\RedCode\\Currency\\Rate\\Provider\\ICurrencyRateProvider');
     $inversedProvider->method('getName')->willReturn($this->inversedProviderName);
     $inversedProvider->method('getBaseCurrency')->willReturn($currencies['RUB']);
     $inversedProvider->method('isInversed')->willReturn(true);
     $notInversedProvider = $this->getMock('\\RedCode\\Currency\\Rate\\Provider\\ICurrencyRateProvider');
     $notInversedProvider->method('getName')->willReturn($this->notInversedProviderName);
     $notInversedProvider->method('getBaseCurrency')->willReturn($currencies['EUR']);
     $notInversedProvider->method('isInversed')->willReturn(false);
     $factory = new ProviderFactory([$inversedProvider, $notInversedProvider]);
     $this->currencyRateManager = $this->getMock('\\RedCode\\Currency\\Rate\\ICurrencyRateManager');
     $this->currencyRateManager->method('getNewInstance')->will($this->returnCallback(function (ICurrency $currency, ICurrencyRateProvider $provider, \DateTime $date, $rateValue, $nominal) {
         $rate = $this->getMock('\\RedCode\\Currency\\Rate\\ICurrencyRate');
         $rate->method('getDate')->willReturn($date);
         $rate->method('getRate')->willReturn($rateValue);
         $rate->method('getNominal')->willReturn($nominal);
         $rate->method('getProviderName')->willReturn($provider->getName());
         $rate->method('getCurrency')->willReturn($currency);
         return $rate;
     }));
     $this->currencyRateManager->method('getRate')->will($this->returnCallback(function (ICurrency $currency, ICurrencyRateProvider $provider, \DateTime $rateDate = null) {
         switch (true) {
             case $provider->getName() == $this->inversedProviderName && $currency->getCode() == 'EUR':
                 $rateValue = 40;
                 break;
             case $provider->getName() == $this->inversedProviderName && $currency->getCode() == 'USD':
                 $rateValue = 30;
                 break;
             case $provider->getName() == $this->notInversedProviderName && $currency->getCode() == 'RUB':
                 $rateValue = 40;
                 break;
             case $provider->getName() == $this->notInversedProviderName && $currency->getCode() == 'USD':
                 $rateValue = 1.13;
                 break;
             default:
                 return null;
         }
         $rate = $this->getMock('\\RedCode\\Currency\\Rate\\ICurrencyRate');
         $rate->method('getDate')->willReturn(!empty($rateDate) ? $rateDate : new \DateTime());
         $rate->method('getRate')->willReturn($rateValue);
         $rate->method('getNominal')->willReturn(1);
         $rate->method('getProviderName')->willReturn($provider->getName());
         $rate->method('getCurrency')->willReturn($currency);
         return $rate;
     }));
     $this->currencyManager = $this->getMock('\\RedCode\\Currency\\ICurrencyManager');
     $this->currencyManager->method('getCurrency')->will($this->returnCallback(function ($name) use($currencies) {
         $name = strtoupper($name);
         if (isset($currencies[$name])) {
             return $currencies[$name];
         }
         return null;
     }));
     $this->currencyManager->method('getAll')->will($this->returnCallback(function () use($currencies) {
         return array_values($currencies);
     }));
     $this->currencyConverter = new CurrencyConverter($factory, $this->currencyRateManager, $this->currencyManager);
     $this->assertInstanceOf('\\RedCode\\Currency\\Rate\\CurrencyConverter', $this->currencyConverter);
 }