aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/intl/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php
blob: ad5581b44b99aa15ca10f7ec7bd9313cddfb4798 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Intl\Tests\NumberFormatter;

use Symfony\Component\Intl\Globals\IntlGlobals;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\NumberFormatter\NumberFormatter;
use Symfony\Component\Intl\Util\IntlTestHelper;

/**
 * Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known
 * behavior of PHP.
 */
abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider formatCurrencyWithDecimalStyleProvider
     */
    public function testFormatCurrencyWithDecimalStyle($value, $currency, $expected)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $this->assertEquals($expected, $formatter->formatCurrency($value, $currency));
    }

    public function formatCurrencyWithDecimalStyleProvider()
    {
        return array(
            array(100, 'ALL', '100'),
            array(100, 'BRL', '100.00'),
            array(100, 'CRC', '100'),
            array(100, 'JPY', '100'),
            array(100, 'CHF', '100'),
            array(-100, 'ALL', '-100'),
            array(-100, 'BRL', '-100'),
            array(-100, 'CRC', '-100'),
            array(-100, 'JPY', '-100'),
            array(-100, 'CHF', '-100'),
            array(1000.12, 'ALL', '1,000.12'),
            array(1000.12, 'BRL', '1,000.12'),
            array(1000.12, 'CRC', '1,000.12'),
            array(1000.12, 'JPY', '1,000.12'),
            array(1000.12, 'CHF', '1,000.12')
        );
    }

    /**
     * @dataProvider formatCurrencyWithCurrencyStyleProvider
     */
    public function testFormatCurrencyWithCurrencyStyle($value, $currency, $expected)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
        $this->assertEquals($expected, $formatter->formatCurrency($value, $currency));
    }

    public function formatCurrencyWithCurrencyStyleProvider()
    {
        return array(
            array(100, 'ALL', 'ALL100'),
            array(-100, 'ALL', '(ALL100)'),
            array(1000.12, 'ALL', 'ALL1,000'),

            array(100, 'JPY', '¥100'),
            array(-100, 'JPY', '(¥100)'),
            array(1000.12, 'JPY', '¥1,000'),

            array(100, 'EUR', '€100.00'),
            array(-100, 'EUR', '(€100.00)'),
            array(1000.12, 'EUR', '€1,000.12'),
        );
    }

    /**
     * @dataProvider formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider
     */
    public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRounding($value, $currency, $symbol, $expected)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
        $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
    }

    public function formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider()
    {
        return array(
            array(100, 'CRC', 'CRC', '%s100'),
            array(-100, 'CRC', 'CRC', '(%s100)'),
            array(1000.12, 'CRC', 'CRC', '%s1,000'),
        );
    }

    /**
     * @dataProvider formatCurrencyWithCurrencyStyleBrazilianRealRoundingProvider
     */
    public function testFormatCurrencyWithCurrencyStyleBrazilianRealRounding($value, $currency, $symbol, $expected)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
        $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
    }

    public function formatCurrencyWithCurrencyStyleBrazilianRealRoundingProvider()
    {
        return array(
            array(100, 'BRL', 'R', '%s$100.00'),
            array(-100, 'BRL', 'R', '(%s$100.00)'),
            array(1000.12, 'BRL', 'R', '%s$1,000.12'),

            // Rounding checks
            array(1000.121, 'BRL', 'R', '%s$1,000.12'),
            array(1000.123, 'BRL', 'R', '%s$1,000.12'),
            array(1000.125, 'BRL', 'R', '%s$1,000.12'),
            array(1000.127, 'BRL', 'R', '%s$1,000.13'),
            array(1000.129, 'BRL', 'R', '%s$1,000.13'),
            array(11.50999, 'BRL', 'R', '%s$11.51'),
            array(11.9999464, 'BRL', 'R', '%s$12.00')
        );
    }

    /**
     * @dataProvider formatCurrencyWithCurrencyStyleSwissRoundingProvider
     */
    public function testFormatCurrencyWithCurrencyStyleSwissRounding($value, $currency, $symbol, $expected)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
        $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
    }

    public function formatCurrencyWithCurrencyStyleSwissRoundingProvider()
    {
        return array(
            array(100, 'CHF', 'CHF', '%s100.00'),
            array(-100, 'CHF', 'CHF', '(%s100.00)'),
            array(1000.12, 'CHF', 'CHF', '%s1,000.10'),
            array('1000.12', 'CHF', 'CHF', '%s1,000.10'),

            // Rounding checks
            array(1000.121, 'CHF', 'CHF', '%s1,000.10'),
            array(1000.123, 'CHF', 'CHF', '%s1,000.10'),
            array(1000.125, 'CHF', 'CHF', '%s1,000.10'),
            array(1000.127, 'CHF', 'CHF', '%s1,000.15'),
            array(1000.129, 'CHF', 'CHF', '%s1,000.15'),

            array(1200000.00, 'CHF', 'CHF', '%s1,200,000.00'),
            array(1200000.1, 'CHF', 'CHF', '%s1,200,000.10'),
            array(1200000.10, 'CHF', 'CHF', '%s1,200,000.10'),
            array(1200000.101, 'CHF', 'CHF', '%s1,200,000.10')
        );
    }

    public function testFormat()
    {
        $errorCode = IntlGlobals::U_ZERO_ERROR;
        $errorMessage = 'U_ZERO_ERROR';

        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $this->assertSame('9.555', $formatter->format(9.555));

        $this->assertSame($errorMessage, $this->getIntlErrorMessage());
        $this->assertSame($errorCode, $this->getIntlErrorCode());
        $this->assertFalse($this->isIntlFailure($this->getIntlErrorCode()));
        $this->assertSame($errorMessage, $formatter->getErrorMessage());
        $this->assertSame($errorCode, $formatter->getErrorCode());
        $this->assertFalse($this->isIntlFailure($formatter->getErrorCode()));
    }

    public function testFormatWithCurrencyStyle()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
        $this->assertEquals('¤1.00', $formatter->format(1));
    }

    /**
     * @dataProvider formatTypeInt32Provider
     */
    public function testFormatTypeInt32($formatter, $value, $expected, $message = '')
    {
        $formattedValue = $formatter->format($value, NumberFormatter::TYPE_INT32);
        $this->assertEquals($expected, $formattedValue, $message);
    }

    public function formatTypeInt32Provider()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        $message = '->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range.';

        return array(
            array($formatter, 1, '1'),
            array($formatter, 1.1, '1'),
            array($formatter, 2147483648, '-2,147,483,648', $message),
            array($formatter, -2147483649, '2,147,483,647', $message),
        );
    }

    /**
     * @dataProvider formatTypeInt32WithCurrencyStyleProvider
     */
    public function testFormatTypeInt32WithCurrencyStyle($formatter, $value, $expected, $message = '')
    {
        $formattedValue = $formatter->format($value, NumberFormatter::TYPE_INT32);
        $this->assertEquals($expected, $formattedValue, $message);
    }

    public function formatTypeInt32WithCurrencyStyleProvider()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);

        $message = '->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range.';

        return array(
            array($formatter, 1, '¤1.00'),
            array($formatter, 1.1, '¤1.00'),
            array($formatter, 2147483648, '(¤2,147,483,648.00)', $message),
            array($formatter, -2147483649, '¤2,147,483,647.00', $message)
        );
    }

    /**
     * The parse() method works differently with integer out of the 32 bit range. format() works fine.
     * @dataProvider formatTypeInt64Provider
     */
    public function testFormatTypeInt64($formatter, $value, $expected)
    {
        $formattedValue = $formatter->format($value, NumberFormatter::TYPE_INT64);
        $this->assertEquals($expected, $formattedValue);
    }

    public function formatTypeInt64Provider()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        return array(
            array($formatter, 1, '1'),
            array($formatter, 1.1, '1'),
            array($formatter, 2147483648, '2,147,483,648'),
            array($formatter, -2147483649, '-2,147,483,649'),
        );
    }

    /**
     * @dataProvider formatTypeInt64WithCurrencyStyleProvider
     */
    public function testFormatTypeInt64WithCurrencyStyle($formatter, $value, $expected)
    {
        $formattedValue = $formatter->format($value, NumberFormatter::TYPE_INT64);
        $this->assertEquals($expected, $formattedValue);
    }

    public function formatTypeInt64WithCurrencyStyleProvider()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);

        return array(
            array($formatter, 1, '¤1.00'),
            array($formatter, 1.1, '¤1.00'),
            array($formatter, 2147483648, '¤2,147,483,648.00'),
            array($formatter, -2147483649, '(¤2,147,483,649.00)')
        );
    }

    /**
     * @dataProvider formatTypeDoubleProvider
     */
    public function testFormatTypeDouble($formatter, $value, $expected)
    {
        $formattedValue = $formatter->format($value, NumberFormatter::TYPE_DOUBLE);
        $this->assertEquals($expected, $formattedValue);
    }

    public function formatTypeDoubleProvider()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        return array(
            array($formatter, 1, '1'),
            array($formatter, 1.1, '1.1'),
        );
    }

    /**
     * @dataProvider formatTypeDoubleWithCurrencyStyleProvider
     */
    public function testFormatTypeDoubleWithCurrencyStyle($formatter, $value, $expected)
    {
        $formattedValue = $formatter->format($value, NumberFormatter::TYPE_DOUBLE);
        $this->assertEquals($expected, $formattedValue);
    }

    public function formatTypeDoubleWithCurrencyStyleProvider()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);

        return array(
            array($formatter, 1, '¤1.00'),
            array($formatter, 1.1, '¤1.10'),
        );
    }

    /**
     * @dataProvider formatTypeCurrencyProvider
     * @expectedException \PHPUnit_Framework_Error_Warning
     */
    public function testFormatTypeCurrency($formatter, $value)
    {
        $formatter->format($value, NumberFormatter::TYPE_CURRENCY);
    }

    /**
     * @dataProvider formatTypeCurrencyProvider
     */
    public function testFormatTypeCurrencyReturn($formatter, $value)
    {
        $this->assertFalse(@$formatter->format($value, NumberFormatter::TYPE_CURRENCY));
    }

    public function formatTypeCurrencyProvider()
    {
        $df = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $cf = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);

        return array(
            array($df, 1),
            array($cf, 1),
        );
    }

    /**
     * @dataProvider formatFractionDigitsProvider
     */
    public function testFormatFractionDigits($value, $expected, $fractionDigits = null, $expectedFractionDigits = 1)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        if (null !== $fractionDigits) {
            $attributeRet = $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $fractionDigits);
        }

        $formattedValue = $formatter->format($value);
        $this->assertSame($expected, $formattedValue);
        $this->assertSame($expectedFractionDigits, $formatter->getAttribute(NumberFormatter::FRACTION_DIGITS));

        if (isset($attributeRet)) {
            $this->assertTrue($attributeRet);
        }
    }

    public function formatFractionDigitsProvider()
    {
        return array(
            array(1.123, '1.123', null, 0),
            array(1.123, '1', 0, 0),
            array(1.123, '1.1', 1, 1),
            array(1.123, '1.12', 2, 2),
            array(1.123, '1', -1, 0),
            array(1.123, '1', 'abc', 0)
        );
    }

    /**
     * @dataProvider formatGroupingUsedProvider
     */
    public function testFormatGroupingUsed($value, $expected, $groupingUsed = null, $expectedGroupingUsed = 1)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        if (null !== $groupingUsed) {
            $attributeRet = $formatter->setAttribute(NumberFormatter::GROUPING_USED, $groupingUsed);
        }

        $formattedValue = $formatter->format($value);
        $this->assertSame($expected, $formattedValue);
        $this->assertSame($expectedGroupingUsed, $formatter->getAttribute(NumberFormatter::GROUPING_USED));

        if (isset($attributeRet)) {
            $this->assertTrue($attributeRet);
        }
    }

    public function formatGroupingUsedProvider()
    {
        return array(
            array(1000, '1,000', null, 1),
            array(1000, '1000', 0, 0),
            array(1000, '1,000', 1, 1),
            array(1000, '1,000', 2, 1),
            array(1000, '1000', 'abc', 0),
            array(1000, '1,000', -1, 1),
        );
    }

    /**
     * @dataProvider formatRoundingModeRoundHalfUpProvider
     */
    public function testFormatRoundingModeHalfUp($value, $expected)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);

        $formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_HALFUP);
        $this->assertSame($expected, $formatter->format($value), '->format() with ROUND_HALFUP rounding mode.');
    }

    public function formatRoundingModeRoundHalfUpProvider()
    {
        // The commented value is differently rounded by intl's NumberFormatter in 32 and 64 bit architectures
        return array(
            array(1.121, '1.12'),
            array(1.123, '1.12'),
            // array(1.125, '1.13'),
            array(1.127, '1.13'),
            array(1.129, '1.13'),
        );
    }

    /**
     * @dataProvider formatRoundingModeRoundHalfDownProvider
     */
    public function testFormatRoundingModeHalfDown($value, $expected)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);

        $formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_HALFDOWN);
        $this->assertSame($expected, $formatter->format($value), '->format() with ROUND_HALFDOWN rounding mode.');
    }

    public function formatRoundingModeRoundHalfDownProvider()
    {
        return array(
            array(1.121, '1.12'),
            array(1.123, '1.12'),
            array(1.125, '1.12'),
            array(1.127, '1.13'),
            array(1.129, '1.13'),
        );
    }

    /**
     * @dataProvider formatRoundingModeRoundHalfEvenProvider
     */
    public function testFormatRoundingModeHalfEven($value, $expected)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);

        $formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_HALFEVEN);
        $this->assertSame($expected, $formatter->format($value), '->format() with ROUND_HALFEVEN rounding mode.');
    }

    public function formatRoundingModeRoundHalfEvenProvider()
    {
        return array(
            array(1.121, '1.12'),
            array(1.123, '1.12'),
            array(1.125, '1.12'),
            array(1.127, '1.13'),
            array(1.129, '1.13'),
        );
    }

    public function testGetLocale()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $this->assertEquals('en', $formatter->getLocale());
    }

    /**
     * @dataProvider parseProvider
     */
    public function testParse($value, $expected, $message = '')
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE);
        $this->assertSame($expected, $parsedValue, $message);

        if ($expected === false) {
            $errorCode = IntlGlobals::U_PARSE_ERROR;
            $errorMessage = 'Number parsing failed: U_PARSE_ERROR';
        } else {
            $errorCode = IntlGlobals::U_ZERO_ERROR;
            $errorMessage = 'U_ZERO_ERROR';
        }

        $this->assertSame($errorMessage, $this->getIntlErrorMessage());
        $this->assertSame($errorCode, $this->getIntlErrorCode());
        $this->assertSame($errorCode !== 0, $this->isIntlFailure($this->getIntlErrorCode()));
        $this->assertSame($errorMessage, $formatter->getErrorMessage());
        $this->assertSame($errorCode, $formatter->getErrorCode());
        $this->assertSame($errorCode !== 0, $this->isIntlFailure($formatter->getErrorCode()));
    }

    public function parseProvider()
    {
        return array(
            array('prefix1', false, '->parse() does not parse a number with a string prefix.'),
            array('1suffix', (float) 1, '->parse() parses a number with a string suffix.'),
        );
    }

    /**
     * @expectedException \PHPUnit_Framework_Error_Warning
     */
    public function testParseTypeDefault()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $formatter->parse('1', NumberFormatter::TYPE_DEFAULT);
    }

    /**
     * @dataProvider parseTypeInt32Provider
     */
    public function testParseTypeInt32($value, $expected, $message = '')
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $parsedValue = $formatter->parse($value, NumberFormatter::TYPE_INT32);
        $this->assertSame($expected, $parsedValue);
    }

    public function parseTypeInt32Provider()
    {
        return array(
            array('1', 1),
            array('1.1', 1),
            array('2,147,483,647', 2147483647),
            array('-2,147,483,648', -2147483647 - 1),
            array('2,147,483,648', false, '->parse() TYPE_INT32 returns false when the number is greater than the integer positive range.'),
            array('-2,147,483,649', false, '->parse() TYPE_INT32 returns false when the number is greater than the integer negative range.')
        );
    }

    public function testParseTypeInt64With32BitIntegerInPhp32Bit()
    {
        IntlTestHelper::require32Bit($this);

        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        $parsedValue = $formatter->parse('2,147,483,647', NumberFormatter::TYPE_INT64);
        $this->assertInternalType('integer', $parsedValue);
        $this->assertEquals(2147483647, $parsedValue);

        $parsedValue = $formatter->parse('-2,147,483,648', NumberFormatter::TYPE_INT64);

        // Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
        // The negative PHP_INT_MAX was being converted to float
        if (
            (version_compare(PHP_VERSION, '5.4.0', '<') && version_compare(PHP_VERSION, '5.3.14', '>=')) ||
            version_compare(PHP_VERSION, '5.4.4', '>=')
        ) {
            $this->assertInternalType('int', $parsedValue);
        } else {
            $this->assertInternalType('float', $parsedValue);
        }

        $this->assertEquals(-2147483648, $parsedValue);
    }

    public function testParseTypeInt64With32BitIntegerInPhp64Bit()
    {
        IntlTestHelper::require64Bit($this);

        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        $parsedValue = $formatter->parse('2,147,483,647', NumberFormatter::TYPE_INT64);
        $this->assertInternalType('integer', $parsedValue);
        $this->assertEquals(2147483647, $parsedValue);

        $parsedValue = $formatter->parse('-2,147,483,648', NumberFormatter::TYPE_INT64);
        $this->assertInternalType('integer', $parsedValue);
        $this->assertEquals(-2147483647 - 1, $parsedValue);
    }

    /**
     * If PHP is compiled in 32bit mode, the returned value for a 64bit integer are float numbers.
     */
    public function testParseTypeInt64With64BitIntegerInPhp32Bit()
    {
        IntlTestHelper::require32Bit($this);

        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        // int 64 using only 32 bit range strangeness
        $parsedValue = $formatter->parse('2,147,483,648', NumberFormatter::TYPE_INT64);
        $this->assertInternalType('float', $parsedValue);
        $this->assertEquals(2147483648, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range.');

        $parsedValue = $formatter->parse('-2,147,483,649', NumberFormatter::TYPE_INT64);
        $this->assertInternalType('float', $parsedValue);
        $this->assertEquals(-2147483649, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range.');
    }

    /**
     * If PHP is compiled in 64bit mode, the returned value for a 64bit integer are 32bit integer numbers.
     */
    public function testParseTypeInt64With64BitIntegerInPhp64Bit()
    {
        IntlTestHelper::require64Bit($this);

        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);

        $parsedValue = $formatter->parse('2,147,483,648', NumberFormatter::TYPE_INT64);
        $this->assertInternalType('integer', $parsedValue);

        // Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
        // A 32 bit integer was being generated instead of a 64 bit integer
        if (
            (version_compare(PHP_VERSION, '5.3.14', '<')) ||
            (version_compare(PHP_VERSION, '5.4.0', '>=') && version_compare(PHP_VERSION, '5.4.4', '<'))
        ) {
            $this->assertEquals(-2147483648, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range (PHP < 5.3.14 and PHP < 5.4.4).');
        } else {
            $this->assertEquals(2147483648, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).');
        }

        $parsedValue = $formatter->parse('-2,147,483,649', NumberFormatter::TYPE_INT64);
        $this->assertInternalType('integer', $parsedValue);

        // Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
        // A 32 bit integer was being generated instead of a 64 bit integer
        if (
            (version_compare(PHP_VERSION, '5.3.14', '<')) ||
            (version_compare(PHP_VERSION, '5.4.0', '>=') && version_compare(PHP_VERSION, '5.4.4', '<'))
        ) {
            $this->assertEquals(2147483647, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range  (PHP < 5.3.14 and PHP < 5.4.4).');
        } else {
            $this->assertEquals(-2147483649, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).');
        }
    }

    /**
     * @dataProvider parseTypeDoubleProvider
     */
    public function testParseTypeDouble($value, $expectedValue)
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE);
        $this->assertSame($expectedValue, $parsedValue);
    }

    public function parseTypeDoubleProvider()
    {
        return array(
            array('1', (float) 1),
            array('1.1', 1.1),
            array('9,223,372,036,854,775,808', 9223372036854775808),
            array('-9,223,372,036,854,775,809', -9223372036854775809),
        );
    }

    /**
     * @expectedException \PHPUnit_Framework_Error_Warning
     */
    public function testParseTypeCurrency()
    {
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $formatter->parse('1', NumberFormatter::TYPE_CURRENCY);
    }

    public function testParseWithNullPositionValue()
    {
        $position = null;
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $formatter->parse('123', NumberFormatter::TYPE_INT32, $position);
        $this->assertNull($position);
    }

    public function testParseWithNotNullPositionValue()
    {
        $position = 1;
        $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
        $formatter->parse('123', NumberFormatter::TYPE_DOUBLE, $position);
        $this->assertEquals(3, $position);
    }

    /**
     * @param string $locale
     * @param null $style
     * @param null $pattern
     *
     * @return \NumberFormatter
     */
    abstract protected function getNumberFormatter($locale = 'en', $style = null, $pattern = null);

    /**
     * @return string
     */
    abstract protected function getIntlErrorMessage();

    /**
     * @return integer
     */
    abstract protected function getIntlErrorCode();

    /**
     * @param integer $errorCode
     *
     * @return Boolean
     */
    abstract protected function isIntlFailure($errorCode);
}