/**
  * @covers ::convert
  */
 public function testConvert()
 {
     $source = $this->getMock('CL\\CurrencyConvert\\NullSource', array('getRateBetween'));
     $converter = new Converter($source);
     $bgn = new Currency('BGN');
     $gbp = new Currency('GBP');
     $source->expects($this->exactly(3))->method('getRateBetween')->will($this->returnValueMap(array(array($bgn, $gbp, 0.5), array($gbp, $bgn, 2))));
     $from = new Money(5000, $bgn);
     $result = $converter->convert($from, $gbp);
     $this->assertEquals(new Money(2500, $gbp), $result);
     $from = new Money(5000, $gbp);
     $result = $converter->convert($from, $bgn);
     $this->assertEquals(new Money(10000, $bgn), $result);
     $from = new Money(155, $bgn);
     $result = $converter->convert($from, $gbp, PHP_ROUND_HALF_DOWN);
     $this->assertEquals(new Money(77, $gbp), $result);
 }
 /**
  * Converts the currency of "getSourceValue" if the currency is different
  * Uses Converter class
  *
  * @return Money
  */
 public function getConvertedSourceValue()
 {
     $currency = $this->getCurrency();
     $value = $this->getSourceValue();
     if ($currency != $value->getCurrency()) {
         $value = Converter::get()->convert($value, $currency);
     }
     return $value;
 }
 public function setUp()
 {
     parent::setUp();
     $this->logger = new TestLogger();
     Converter::initialize(new NullSource());
     DB::setConfig(['dsn' => 'mysql:dbname=clippings/transfer;host=127.0.0.1', 'username' => 'root']);
     DB::get()->execute('ALTER TABLE Basket AUTO_INCREMENT = 1');
     DB::get()->execute('ALTER TABLE ProductItem AUTO_INCREMENT = 1');
     DB::get()->setLogger($this->logger);
     DB::get()->beginTransaction();
     Container::clear();
 }
 public function setUp()
 {
     parent::setUp();
     $this->logger = new TestLogger();
     DB::setConfig(['dsn' => 'mysql:dbname=clippings/purchases;host=127.0.0.1', 'username' => 'root', 'escaping' => DB::ESCAPING_MYSQL]);
     Converter::initialize(new NullSource());
     DB::get()->execute('ALTER TABLE PurchaseItem AUTO_INCREMENT = 6');
     DB::get()->execute('ALTER TABLE StorePurchase AUTO_INCREMENT = 3');
     DB::get()->setLogger($this->logger);
     DB::get()->beginTransaction();
     Container::clear();
 }
Exemple #5
0
 public function setUp()
 {
     parent::setUp();
     Converter::initialize(new NullSource());
     Container::clear();
 }