@@ -707,22 +707,36 @@ public function testGetPattern()
707
707
$ formatter ->getPattern ();
708
708
}
709
709
710
- /**
711
- * @expectedException \Symfony\Component\Locale\Exception\MethodNotImplementedException
712
- */
713
710
public function testGetSymbol ()
714
711
{
715
- $ formatter = $ this ->getStubFormatterWithDecimalStyle ();
716
- $ formatter ->getSymbol (null );
712
+ $ this ->skipIfIntlExtensionIsNotLoaded ();
713
+
714
+ $ intlDecimalFormatter = new \NumberFormatter ('en ' , \NumberFormatter::DECIMAL );
715
+ $ intlCurrencyFormatter = new \NumberFormatter ('en ' , \NumberFormatter::CURRENCY );
716
+
717
+ $ stubDecimalFormatter = $ this ->getStubFormatterWithDecimalStyle ();
718
+ $ stubCurrencyFormatter = $ this ->getStubFormatterWithCurrencyStyle ();
719
+
720
+ for ($ i = 0 ; $ i <= 17 ; $ i ++) {
721
+ $ this ->assertSame ($ stubDecimalFormatter ->getSymbol ($ i ), $ intlDecimalFormatter ->getSymbol ($ i ), $ i );
722
+ $ this ->assertSame ($ stubCurrencyFormatter ->getSymbol ($ i ), $ intlCurrencyFormatter ->getSymbol ($ i ), $ i );
723
+ }
717
724
}
718
725
719
- /**
720
- * @expectedException \Symfony\Component\Locale\Exception\MethodNotImplementedException
721
- */
722
726
public function testGetTextAttribute ()
723
727
{
724
- $ formatter = $ this ->getStubFormatterWithDecimalStyle ();
725
- $ formatter ->getTextAttribute (null );
728
+ $ this ->skipIfIntlExtensionIsNotLoaded ();
729
+
730
+ $ intlDecimalFormatter = new \NumberFormatter ('en ' , \NumberFormatter::DECIMAL );
731
+ $ intlCurrencyFormatter = new \NumberFormatter ('en ' , \NumberFormatter::CURRENCY );
732
+
733
+ $ stubDecimalFormatter = $ this ->getStubFormatterWithDecimalStyle ();
734
+ $ stubCurrencyFormatter = $ this ->getStubFormatterWithCurrencyStyle ();
735
+
736
+ for ($ i = 0 ; $ i <= 5 ; $ i ++) {
737
+ $ this ->assertSame ($ stubDecimalFormatter ->getTextAttribute ($ i ), $ intlDecimalFormatter ->getTextAttribute ($ i ), $ i );
738
+ $ this ->assertSame ($ stubCurrencyFormatter ->getTextAttribute ($ i ), $ intlCurrencyFormatter ->getTextAttribute ($ i ), 'fooo ' .$ i );
739
+ }
726
740
}
727
741
728
742
/**
@@ -737,11 +751,13 @@ public function testParseCurrency()
737
751
/**
738
752
* @dataProvider parseProvider
739
753
*/
740
- public function testParseStub ($ value , $ expected , $ message = '' )
754
+ public function testParseStub ($ value , $ expected , $ message, $ expectedPosition )
741
755
{
742
756
$ formatter = $ this ->getStubFormatterWithDecimalStyle ();
743
- $ parsedValue = $ formatter ->parse ($ value , StubNumberFormatter::TYPE_DOUBLE );
757
+ $ position = 0 ;
758
+ $ parsedValue = $ formatter ->parse ($ value , StubNumberFormatter::TYPE_DOUBLE , $ position );
744
759
$ this ->assertSame ($ expected , $ parsedValue , $ message );
760
+ $ this ->assertSame ($ expectedPosition , $ position , $ message );
745
761
746
762
if ($ expected === false ) {
747
763
$ errorCode = StubIntl::U_PARSE_ERROR ;
@@ -762,14 +778,16 @@ public function testParseStub($value, $expected, $message = '')
762
778
/**
763
779
* @dataProvider parseProvider
764
780
*/
765
- public function testParseIntl ($ value , $ expected , $ message = '' )
781
+ public function testParseIntl ($ value , $ expected , $ message, $ expectedPosition )
766
782
{
767
783
$ this ->skipIfIntlExtensionIsNotLoaded ();
768
784
$ this ->skipIfICUVersionIsTooOld ();
769
785
770
786
$ formatter = $ this ->getIntlFormatterWithDecimalStyle ();
771
- $ parsedValue = $ formatter ->parse ($ value , \NumberFormatter::TYPE_DOUBLE );
787
+ $ position = 0 ;
788
+ $ parsedValue = $ formatter ->parse ($ value , \NumberFormatter::TYPE_DOUBLE , $ position );
772
789
$ this ->assertSame ($ expected , $ parsedValue , $ message );
790
+ $ this ->assertSame ($ expectedPosition , $ position , $ message );
773
791
774
792
if ($ expected === false ) {
775
793
$ errorCode = StubIntl::U_PARSE_ERROR ;
@@ -790,8 +808,8 @@ public function testParseIntl($value, $expected, $message = '')
790
808
public function parseProvider ()
791
809
{
792
810
return array (
793
- array ('prefix1 ' , false , '->parse() does not parse a number with a string prefix. ' ),
794
- array ('1suffix ' , (float ) 1 , '->parse() parses a number with a string suffix. ' ),
811
+ array ('prefix1 ' , false , '->parse() does not parse a number with a string prefix. ' , 0 ),
812
+ array ('1.4suffix ' , (float ) 1.4 , '->parse() parses a number with a string suffix. ' , 3 ),
795
813
);
796
814
}
797
815
@@ -840,6 +858,7 @@ public function parseTypeInt32Provider()
840
858
return array (
841
859
array ('1 ' , 1 ),
842
860
array ('1.1 ' , 1 ),
861
+ array ('.1 ' , 0 ),
843
862
array ('2,147,483,647 ' , 2147483647 ),
844
863
array ('-2,147,483,648 ' , -2147483647 - 1 ),
845
864
array ('2,147,483,648 ' , false , '->parse() TYPE_INT32 returns false when the number is greater than the integer positive range. ' ),
@@ -1104,10 +1123,10 @@ public function testParseTypeCurrencyIntl()
1104
1123
1105
1124
public function testParseWithNullPositionValueStub ()
1106
1125
{
1107
- $ position = null ;
1126
+ $ position = 0 ;
1108
1127
$ formatter = $ this ->getStubFormatterWithDecimalStyle ();
1109
1128
$ formatter ->parse ('123 ' , StubNumberFormatter::TYPE_INT32 , $ position );
1110
- $ this ->assertNull ( $ position );
1129
+ $ this ->assertEquals ( 3 , $ position );
1111
1130
}
1112
1131
1113
1132
public function testParseWithNullPositionValueIntl ()
@@ -1119,14 +1138,12 @@ public function testParseWithNullPositionValueIntl()
1119
1138
$ this ->assertEquals (3 , $ position );
1120
1139
}
1121
1140
1122
- /**
1123
- * @expectedException \Symfony\Component\Locale\Exception\MethodArgumentNotImplementedException
1124
- */
1125
1141
public function testParseWithNotNullPositionValueStub ()
1126
1142
{
1127
1143
$ position = 1 ;
1128
1144
$ formatter = $ this ->getStubFormatterWithDecimalStyle ();
1129
1145
$ formatter ->parse ('123 ' , StubNumberFormatter::TYPE_INT32 , $ position );
1146
+ $ this ->assertEquals (3 , $ position );
1130
1147
}
1131
1148
1132
1149
public function testParseWithNotNullPositionValueIntl ()
0 commit comments