class InputTest in Currency 7.2
Tests \BartFeenstra\Currency\Input
Hierarchy
- class \BartFeenstra\Tests\Currency\InputTest extends \BartFeenstra\Tests\Currency\PHPUnit_Framework_TestCase
Expanded class hierarchy of InputTest
File
- currency/
vendor/ bartfeenstra/ currency/ src/ BartFeenstra/ Tests/ Currency/ InputTest.php, line 17 - Contains class \BartFeenstra\Tests\Currency\ParseTest.
Namespace
BartFeenstra\Tests\CurrencyView source
class InputTest extends \PHPUnit_Framework_TestCase {
/**
* Tests amount().
*/
function testParseAmount() {
$amounts_invalid = array(
'BartFeenstra\\Currency\\AmountNotNumericException' => array(
'a',
'a123',
'123%',
),
'BartFeenstra\\Currency\\AmountInvalidDecimalSeparatorException' => array(
'.5.',
'123,456,789.00,00',
),
);
foreach ($amounts_invalid as $exception_class => $amounts) {
foreach ($amounts as $amount) {
$valid = TRUE;
try {
Input::parseAmount($amount);
} catch (\Exception $e) {
if ($e instanceof $exception_class) {
$valid = FALSE;
}
}
$this
->assertFalse($valid);
}
}
$amounts_valid = array(
// Integers.
array(
123,
'123',
),
// Floats.
array(
123.456,
'123.456',
),
array(
-123.456,
'-123.456',
),
// Integer strings.
array(
'123',
'123',
),
// Decimal strings using different decimal separators.
array(
'123.456',
'123.456',
),
array(
'123,456',
'123.456',
),
array(
'123٫456',
'123.456',
),
array(
'123/456',
'123.456',
),
// Negative strings.
array(
'-123',
'-123',
),
array(
'(123)',
'-123',
),
array(
'123-',
'-123',
),
array(
'--123',
'123',
),
array(
'(--123-)',
'123',
),
);
foreach ($amounts_valid as $amount) {
$amount_validated = NULL;
$amount_validated = Input::parseAmount($amount[0]);
$this
->assertSame($amount_validated, $amount[1]);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InputTest:: |
function | Tests amount(). |