Пример #1
0
 /**
  * @expectedException \JBZoo\SimpleTypes\Exception
  */
 public function testNoValidTypes()
 {
     $money = new Money('1 usd', new ConfigMoney());
     $weight = new Weight('1 kg', new ConfigTestWeight());
     $money->add($weight);
 }
Пример #2
0
 public function testEmptyValid()
 {
     $money = new Money('1 i', new ConfigTestEmpty());
     is('1 i', $money->dump(false));
 }
Пример #3
0
$money = new Money('10 eur');
$money = new Weight('1000');
// Gram is default in the ConfigWeight class
$money = new Length('500 km');
$money = new Money('100500 usd', new ConfigMoney());
// my custom params only for that object
// Smart parser can find number, understand decimal symbol, trim, letter cases, e.t.c...
$money = new Money(' - 1 2 3 , 4 5 6 rub ');
// Equals -123.456 rubles
$money = new Money('1.0e+18 EUR ');
// Really huge number
$money = new Money('  EuR 3,50   ');
$money = new Money('usd');
// Different ways to use basic arithmetic
// example #1
$usd = new Money('10 usd');
$usd->add(new Money('10 eur'));
// example #2
$usd = (new Money('10 usd'))->add(new Money('10 eur'));
// example #3
$usd->add('10 eur');
// example #4
$usd->add('10');
// eur is default in the ConfigMoney
// example #5
$usd->add(['10', 'eur']);
// Chaining method calls
$money = (new Money('4.95 usd'))->add('10 usd')->subtract('2 eur')->negative()->getClone()->division(5)->multiply(10)->convert('eur')->customFunc(function (Money $value) {
    // custom handler
    $value->add(new Money('600 rub'))->add('-500%');
    // -4.2€