public function testOverrideCurrency()
 {
     \Locale::setDefault("fr_FR");
     $form = $this->factory->create($this->simpleMoneyTypeClass, null, ["currency" => "USD"]);
     $form->submit(array("tbbc_amount" => '1 252,5'));
     $this->assertEquals(Money::USD(125250), $form->getData());
 }
Пример #2
0
 public function widthdrawl($amount)
 {
     $originalfunds = Money::USD((int) $this->fundsavailable);
     $addedFunds = Money::USD((int) $amount);
     $fundsavailable = $originalfunds->subtract($addedFunds);
     $this->fundsavailable = $fundsavailable->getAmount();
     $this->save();
 }
Пример #3
0
 /** @test */
 public function ConvertsEurToUsdWithModes()
 {
     $eur = Money::Euro(10);
     $pair = new CurrencyPair(CurrencyProxy::determine('EUR'), CurrencyProxy::determine('USD'), 1.25);
     $usd = $pair->convert($eur);
     $this->assertEquals(Money::USD(13), $usd);
     $pair = new CurrencyPair(CurrencyProxy::determine('EUR'), CurrencyProxy::determine('USD'), 1.25);
     $usd = $pair->convert($eur, new RoundingMode(RoundingMode::ROUND_HALF_DOWN));
     $this->assertEquals(Money::USD(12), $usd);
 }
 /** @test */
 public function ConvertsEurToUsdAndBack()
 {
     $eur = Money::EUR(100);
     $pair = new CurrencyPair(new Currency('EUR'), new Currency('USD'), 1.25);
     $usd = $pair->convert($eur);
     $this->assertEquals(Money::USD(125), $usd);
     $pair = new CurrencyPair(new Currency('USD'), new Currency('EUR'), 0.8);
     $eur = $pair->convert($usd);
     $this->assertEquals(Money::EUR(100), $eur);
 }
Пример #5
0
 public function testMoneyTwigExtension()
 {
     \Locale::setDefault('en');
     /** @var PairManagerInterface $pairManager */
     $pairManager = $this->client->getContainer()->get("tbbc_money.pair_manager");
     $pairManager->saveRatio("USD", 1.25);
     /** @var MoneyExtension $moneyExtension */
     $moneyExtension = $this->client->getContainer()->get("tbbc_money.twig.money");
     $eur = Money::EUR(100);
     $usd = $moneyExtension->convert($eur, "USD");
     $this->assertEquals(Money::USD(125), $usd);
 }
Пример #6
0
 public function testRatio()
 {
     $eur = Money::EUR(100);
     $sameEur = $this->manager->convert($eur, "EUR");
     $this->assertEquals(Money::EUR(100), $sameEur);
     try {
         $this->manager->convert($eur, "USD");
         $this->assertTrue(false);
     } catch (MoneyException $e) {
         $this->assertTrue(true);
     }
     $this->manager->saveRatio("USD", 1.25);
     $usd = $this->manager->convert($eur, "USD");
     $this->assertEquals(Money::USD(125), $usd);
     $this->manager->saveRatio("CAD", 1.5);
     $cad = $this->manager->convert($usd, "CAD");
     $this->assertEquals(Money::CAD(150), $cad);
 }
Пример #7
0
 public function setUp()
 {
     $this->money_usd = Money::USD(1234);
     $this->money_euro = Money::Euro(1234);
     $this->money_czech = Money::Koruna(1234);
 }
Пример #8
0
 /**
  * @expectedException Money\InvalidArgumentException
  */
 public function testDifferentCurrenciesCannotBeCompared()
 {
     Money::EUR(1)->compare(Money::USD(1));
 }
Пример #9
0
 public function testConstructorWithMoney()
 {
     $price = new Price([Money::EUR(5), Money::USD(10), Money::GBP(10), 'TRY' => 120], [CurrencyPair::createFromIso('USD/CHF 1.5'), CurrencyPair::createFromIso('USD/AWG 1.0')]);
     $this->assertInstanceOf('Leaphly\\Price\\Price', $price);
     $this->assertEquals(15, $price->getAmount('CHF'));
 }
Пример #10
0
 public function testCents()
 {
     $this->assertEquals(Money::USD(1234)->getCents(), Money::USD(1234)->getUnits());
 }
Пример #11
0
 public function chargeFee($amount, $percentage = 0.029, $flat = 30)
 {
     $amount = Money::USD($amount);
     $flatfee = Money::USD($flat);
     $fee = $amount->multiply($percentage);
     $newAmount = $amount->subtract($fee);
     $newAmount = $newAmount->subtract($flatfee);
     return $newAmount->getAmount();
 }
Пример #12
0
 /**
  * @test
  */
 public function itSetsMoney()
 {
     $expense = new Expense();
     $expense->setMoney($money = Money::USD(1000));
     $this->assertEquals($money, $expense->getMoney());
 }