Skip to content

Commit

Permalink
Add formatByFormatter method
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Sep 19, 2017
1 parent 780b8af commit 062d38d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Money\Currency;
use Money\Formatter\DecimalMoneyFormatter;
use Money\Formatter\IntlMoneyFormatter;
use Money\MoneyFormatter;
use NumberFormatter;

/**
Expand Down Expand Up @@ -333,6 +334,18 @@ public function formatSimple(Currencies $currencies = null)
return $formatter->format($this->money);
}

/**
* Format by formatter.
*
* @param \Money\MoneyFormatter $formatter
*
* @return string
*/
public function formatByFormatter(MoneyFormatter $formatter)
{
return $formatter->format($this->money);
}

/**
* Json serialize.
*
Expand Down
8 changes: 8 additions & 0 deletions tests/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Money\Currencies\ISOCurrencies;
use Money\Currency;
use Money\Formatter\DecimalMoneyFormatter;

/**
* @covers \Cknow\Money\Money
Expand Down Expand Up @@ -76,4 +77,11 @@ public function testFormatSimple()
$this->assertEquals('1.00', Money::BRL(100)->formatSimple(Money::getCurrencies()));
$this->assertEquals('1.00', Money::BRL(100)->formatSimple());
}

public function testFormatByFormatter()
{
$formatter = new DecimalMoneyFormatter(Money::getCurrencies());

$this->assertEquals('1.00', Money::BRL(100)->formatByFormatter($formatter));
}
}

0 comments on commit 062d38d

Please sign in to comment.