forked from LiveCarta/PayPal-PHP-SDK
Updated FormatConverter to Format Price based on Currency (if provided)
- Fixes #176 Issue - Renamed formatToTwoDecimalPlaces to formatToNumber
This commit is contained in:
@@ -12,7 +12,8 @@ use PayPal\Test\Validation\NumericValidatorTest;
|
||||
class FormatConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public static function classMethodListProvider(){
|
||||
public static function classMethodListProvider()
|
||||
{
|
||||
return array(
|
||||
array(new Item(), 'Price'),
|
||||
array(new Item(), 'Tax'),
|
||||
@@ -29,6 +30,14 @@ class FormatConverterTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public static function CurrencyListWithNoDecimalsProvider()
|
||||
{
|
||||
return array(
|
||||
array('JPY'),
|
||||
array('TWD')
|
||||
);
|
||||
}
|
||||
|
||||
public static function apiModelSettersProvider()
|
||||
{
|
||||
$provider = array();
|
||||
@@ -62,6 +71,44 @@ class FormatConverterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider CurrencyListWithNoDecimalsProvider
|
||||
*/
|
||||
public function testPriceWithNoDecimalCurrencyInvalid($input)
|
||||
{
|
||||
try {
|
||||
FormatConverter::formatToPrice("1.234", $input);
|
||||
} catch (\InvalidArgumentException $ex) {
|
||||
$this->assertContains("value cannot have decimals for", $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider CurrencyListWithNoDecimalsProvider
|
||||
*/
|
||||
public function testPriceWithNoDecimalCurrencyValid($input)
|
||||
{
|
||||
$result = FormatConverter::formatToPrice("1.0000000", $input);
|
||||
$this->assertEquals("1", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider \PayPal\Test\Validation\NumericValidatorTest::positiveProvider
|
||||
*/
|
||||
public function testFormatToNumber($input, $expected)
|
||||
{
|
||||
$result = FormatConverter::formatToNumber($input);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testFormatToNumberDecimals()
|
||||
{
|
||||
$result = FormatConverter::formatToNumber("0.0", 4);
|
||||
$this->assertEquals("0.0000", $result);
|
||||
}
|
||||
|
||||
|
||||
public function testFormat()
|
||||
{
|
||||
$result = FormatConverter::format("12.0123", "%0.2f");
|
||||
|
||||
Reference in New Issue
Block a user