@@ -25,14 +25,17 @@ class DateTimeToLocalizedStringTransformerTest extends BaseDateTimeTransformerTe
2525 protected $ dateTimeWithoutSeconds ;
2626 private $ defaultLocale ;
2727
28+ private $ initialTestCaseUseException ;
29+ private $ initialTestCaseErrorLevel ;
30+
2831 protected function setUp (): void
2932 {
3033 parent ::setUp ();
3134
3235 // Normalize intl. configuration settings.
3336 if (\extension_loaded ('intl ' )) {
34- $ this ->iniSet ('intl.use_exceptions ' , 0 );
35- $ this ->iniSet ('intl.error_level ' , 0 );
37+ $ this ->initialTestCaseUseException = ini_set ('intl.use_exceptions ' , 0 );
38+ $ this ->initialTestCaseErrorLevel = ini_set ('intl.error_level ' , 0 );
3639 }
3740
3841 // Since we test against "de_AT", we need the full implementation
@@ -50,6 +53,11 @@ protected function tearDown(): void
5053 $ this ->dateTime = null ;
5154 $ this ->dateTimeWithoutSeconds = null ;
5255 \Locale::setDefault ($ this ->defaultLocale );
56+
57+ if (\extension_loaded ('intl ' )) {
58+ ini_set ('intl.use_exceptions ' , $ this ->initialTestCaseUseException );
59+ ini_set ('intl.error_level ' , $ this ->initialTestCaseUseException );
60+ }
5361 }
5462
5563 public static function dataProvider ()
@@ -339,11 +347,15 @@ public function testReverseTransformWrapsIntlErrorsWithErrorLevel()
339347 $ this ->markTestSkipped ('intl extension is not loaded ' );
340348 }
341349
342- $ this -> iniSet ('intl.error_level ' , \E_WARNING );
350+ $ errorLevel = ini_set ('intl.error_level ' , \E_WARNING );
343351
344- $ this ->expectException (TransformationFailedException::class);
345- $ transformer = new DateTimeToLocalizedStringTransformer ();
346- $ transformer ->reverseTransform ('12345 ' );
352+ try {
353+ $ this ->expectException (TransformationFailedException::class);
354+ $ transformer = new DateTimeToLocalizedStringTransformer ();
355+ $ transformer ->reverseTransform ('12345 ' );
356+ } finally {
357+ ini_set ('intl.error_level ' , $ errorLevel );
358+ }
347359 }
348360
349361 public function testReverseTransformWrapsIntlErrorsWithExceptions ()
@@ -352,11 +364,15 @@ public function testReverseTransformWrapsIntlErrorsWithExceptions()
352364 $ this ->markTestSkipped ('intl extension is not loaded ' );
353365 }
354366
355- $ this -> iniSet ('intl.use_exceptions ' , 1 );
367+ $ initialUseExceptions = ini_set ('intl.use_exceptions ' , 1 );
356368
357- $ this ->expectException (TransformationFailedException::class);
358- $ transformer = new DateTimeToLocalizedStringTransformer ();
359- $ transformer ->reverseTransform ('12345 ' );
369+ try {
370+ $ this ->expectException (TransformationFailedException::class);
371+ $ transformer = new DateTimeToLocalizedStringTransformer ();
372+ $ transformer ->reverseTransform ('12345 ' );
373+ } finally {
374+ ini_set ('intl.use_exceptions ' , $ initialUseExceptions );
375+ }
360376 }
361377
362378 public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel ()
@@ -365,12 +381,17 @@ public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel()
365381 $ this ->markTestSkipped ('intl extension is not loaded ' );
366382 }
367383
368- $ this -> iniSet ('intl.use_exceptions ' , 1 );
369- $ this -> iniSet ('intl.error_level ' , \E_WARNING );
384+ $ initialUseExceptions = ini_set ('intl.use_exceptions ' , 1 );
385+ $ initialErrorLevel = ini_set ('intl.error_level ' , \E_WARNING );
370386
371- $ this ->expectException (TransformationFailedException::class);
372- $ transformer = new DateTimeToLocalizedStringTransformer ();
373- $ transformer ->reverseTransform ('12345 ' );
387+ try {
388+ $ this ->expectException (TransformationFailedException::class);
389+ $ transformer = new DateTimeToLocalizedStringTransformer ();
390+ $ transformer ->reverseTransform ('12345 ' );
391+ } finally {
392+ ini_set ('intl.use_exceptions ' , $ initialUseExceptions );
393+ ini_set ('intl.error_level ' , $ initialErrorLevel );
394+ }
374395 }
375396
376397 protected function createDateTimeTransformer (?string $ inputTimezone = null , ?string $ outputTimezone = null ): BaseDateTimeTransformer
0 commit comments