public function testRatioProvider() { $provider = new RateExchangeRatioProvider(); $this->manager->setRatioProvider($provider); $this->manager->saveRatioListFromRatioProvider(); $ratio = $this->manager->getRelativeRatio("EUR", "USD"); $this->assertTrue($ratio > 0.3); $this->assertTrue($ratio < 3); $referenceRatio = $provider->fetchRatio("EUR", "CAD"); $this->assertEquals($referenceRatio, $this->manager->getRelativeRatio("EUR", "CAD")); }
public function testRatioProvider() { $provider = new YahooFinanceRatioProvider(); $this->manager->setRatioProvider($provider); $this->manager->saveRatioListFromRatioProvider(); $ratio = $this->manager->getRelativeRatio("EUR", "USD"); $this->assertTrue($ratio > 0.3); $this->assertTrue($ratio < 3); $referenceRatio = $provider->fetchRatio("EUR", "CAD"); //The currency exchange rate are updated every seconds //The round is a workaround to negate the variation between the two ratio fetches $this->assertEquals(ROUND($referenceRatio, 2), ROUND($this->manager->getRelativeRatio("EUR", "CAD"), 2)); }
public function testRatioProvider() { //Provider $provider = new StaticRatioProvider(); $provider->setRatio('EUR', 'USD', 1.08); $provider->setRatio('EUR', 'CAD', 1.54); //Store rates in manager $this->manager->setRatioProvider($provider); $this->manager->saveRatioListFromRatioProvider(); //Check saved rates $this->assertSame(1.08, $this->manager->getRelativeRatio("EUR", "USD")); $this->assertSame(1.54, $this->manager->getRelativeRatio("EUR", "CAD")); //Change provider rates and make sure stored rates are not touched $provider->setRatio('EUR', 'USD', 2.2); $provider->setRatio('EUR', 'CAD', 1.83); $this->assertSame(1.08, $this->manager->getRelativeRatio("EUR", "USD")); $this->assertSame(1.54, $this->manager->getRelativeRatio("EUR", "CAD")); }