11
11
12
12
namespace Symfony \Component \Intl \Tests \NumberFormatter ;
13
13
14
- use PHPUnit \Framework \Error \Warning ;
15
14
use PHPUnit \Framework \TestCase ;
16
15
use Symfony \Component \Intl \Globals \IntlGlobals ;
17
16
use Symfony \Component \Intl \NumberFormatter \NumberFormatter ;
@@ -328,13 +327,17 @@ public function testFormatTypeCurrency($formatter, $value)
328
327
{
329
328
if (\PHP_VERSION_ID >= 80000 ) {
330
329
$ this ->expectException (\ValueError::class);
331
- } elseif (method_exists ($ this , 'expectWarning ' )) {
332
- $ this ->expectWarning ();
333
330
} else {
334
- $ this ->expectException (Warning ::class);
331
+ $ this ->expectException (\ErrorException ::class);
335
332
}
336
333
337
- $ formatter ->format ($ value , NumberFormatter::TYPE_CURRENCY );
334
+ set_error_handler ([self ::class, 'throwOnWarning ' ]);
335
+
336
+ try {
337
+ $ formatter ->format ($ value , NumberFormatter::TYPE_CURRENCY );
338
+ } finally {
339
+ restore_error_handler ();
340
+ }
338
341
}
339
342
340
343
/**
@@ -705,16 +708,21 @@ public static function parseProvider()
705
708
706
709
public function testParseTypeDefault ()
707
710
{
711
+ $ formatter = static ::getNumberFormatter ('en ' , NumberFormatter::DECIMAL );
712
+
708
713
if (\PHP_VERSION_ID >= 80000 ) {
709
714
$ this ->expectException (\ValueError::class);
710
- } elseif (method_exists ($ this , 'expectWarning ' )) {
711
- $ this ->expectWarning ();
712
715
} else {
713
- $ this ->expectException (Warning ::class);
716
+ $ this ->expectException (\ErrorException ::class);
714
717
}
715
718
716
- $ formatter = static ::getNumberFormatter ('en ' , NumberFormatter::DECIMAL );
717
- $ formatter ->parse ('1 ' , NumberFormatter::TYPE_DEFAULT );
719
+ set_error_handler ([self ::class, 'throwOnWarning ' ]);
720
+
721
+ try {
722
+ $ formatter ->parse ('1 ' , NumberFormatter::TYPE_DEFAULT );
723
+ } finally {
724
+ restore_error_handler ();
725
+ }
718
726
}
719
727
720
728
/**
@@ -831,16 +839,21 @@ public static function parseTypeDoubleProvider()
831
839
832
840
public function testParseTypeCurrency ()
833
841
{
842
+ $ formatter = static ::getNumberFormatter ('en ' , NumberFormatter::DECIMAL );
843
+
834
844
if (\PHP_VERSION_ID >= 80000 ) {
835
845
$ this ->expectException (\ValueError::class);
836
- } elseif (method_exists ($ this , 'expectWarning ' )) {
837
- $ this ->expectWarning ();
838
846
} else {
839
- $ this ->expectException (Warning ::class);
847
+ $ this ->expectException (\ErrorException ::class);
840
848
}
841
849
842
- $ formatter = static ::getNumberFormatter ('en ' , NumberFormatter::DECIMAL );
843
- $ formatter ->parse ('1 ' , NumberFormatter::TYPE_CURRENCY );
850
+ set_error_handler ([self ::class, 'throwOnWarning ' ]);
851
+
852
+ try {
853
+ $ formatter ->parse ('1 ' , NumberFormatter::TYPE_CURRENCY );
854
+ } finally {
855
+ restore_error_handler ();
856
+ }
844
857
}
845
858
846
859
public function testParseWithNotNullPositionValue ()
@@ -864,4 +877,13 @@ abstract protected function getIntlErrorCode(): int;
864
877
* @param int $errorCode
865
878
*/
866
879
abstract protected function isIntlFailure ($ errorCode ): bool ;
880
+
881
+ public static function throwOnWarning (int $ errno , string $ errstr , string $ errfile = null , int $ errline = null ): bool
882
+ {
883
+ if ($ errno & (\E_WARNING | \E_USER_WARNING )) {
884
+ throw new \ErrorException ($ errstr , 0 , $ errno , $ errfile ?? __FILE__ , $ errline ?? __LINE__ );
885
+ }
886
+
887
+ return false ;
888
+ }
867
889
}
0 commit comments