|
| 1 | +--TEST-- |
| 2 | +ValueErrors for format/parse methods and procedural functions |
| 3 | +--EXTENSIONS-- |
| 4 | +intl |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +$o = new NumberFormatter('en_US', NumberFormatter::PATTERN_DECIMAL); |
| 9 | +$num = 5; |
| 10 | +$str = "string"; |
| 11 | + |
| 12 | +/* Unknown type constant */ |
| 13 | +try { |
| 14 | + numfmt_format($o, $num, -20); |
| 15 | +} catch (\ValueError $e) { |
| 16 | + echo $e->getMessage(), \PHP_EOL; |
| 17 | +} |
| 18 | +try { |
| 19 | + $o->format($num, -20); |
| 20 | +} catch (\ValueError $e) { |
| 21 | + echo $e->getMessage(), \PHP_EOL; |
| 22 | +} |
| 23 | +try { |
| 24 | + numfmt_parse($o, $str, -20); |
| 25 | +} catch (\ValueError $e) { |
| 26 | + echo $e->getMessage(), \PHP_EOL; |
| 27 | +} |
| 28 | +try { |
| 29 | + $o->parse($str, -20); |
| 30 | +} catch (\ValueError $e) { |
| 31 | + echo $e->getMessage(), \PHP_EOL; |
| 32 | +} |
| 33 | + |
| 34 | +/* With NumberFormatter::TYPE_CURRENCY */ |
| 35 | +try { |
| 36 | + numfmt_format($o, $num, NumberFormatter::TYPE_CURRENCY); |
| 37 | +} catch (\ValueError $e) { |
| 38 | + echo $e->getMessage(), \PHP_EOL; |
| 39 | +} |
| 40 | +try { |
| 41 | + $o->format($num, NumberFormatter::TYPE_CURRENCY); |
| 42 | +} catch (\ValueError $e) { |
| 43 | + echo $e->getMessage(), \PHP_EOL; |
| 44 | +} |
| 45 | +try { |
| 46 | + numfmt_parse($o, $str, NumberFormatter::TYPE_CURRENCY); |
| 47 | +} catch (\ValueError $e) { |
| 48 | + echo $e->getMessage(), \PHP_EOL; |
| 49 | +} |
| 50 | +try { |
| 51 | + $o->parse($str, NumberFormatter::TYPE_CURRENCY); |
| 52 | +} catch (\ValueError $e) { |
| 53 | + echo $e->getMessage(), \PHP_EOL; |
| 54 | +} |
| 55 | + |
| 56 | +?> |
| 57 | +--EXPECT-- |
| 58 | +numfmt_format(): Argument #3 ($type) must be a NumberFormatter::TYPE_* constant |
| 59 | +NumberFormatter::format(): Argument #2 ($type) must be a NumberFormatter::TYPE_* constant |
| 60 | +numfmt_parse(): Argument #3 ($type) must be a NumberFormatter::TYPE_* constant |
| 61 | +NumberFormatter::parse(): Argument #2 ($type) must be a NumberFormatter::TYPE_* constant |
| 62 | +numfmt_format(): Argument #3 ($type) cannot be NumberFormatter::TYPE_CURRENCY constant, use numfmt_format_currency() function instead |
| 63 | +NumberFormatter::format(): Argument #2 ($type) cannot be NumberFormatter::TYPE_CURRENCY constant, use NumberFormatter::formatCurrency() method instead |
| 64 | +numfmt_parse(): Argument #3 ($type) cannot be NumberFormatter::TYPE_CURRENCY constant, use numfmt_parse_currency() function instead |
| 65 | +NumberFormatter::parse(): Argument #2 ($type) cannot be NumberFormatter::TYPE_CURRENCY constant, use NumberFormatter::parseCurrency() method instead |
0 commit comments