From 08c924b8a706c03406e77278e16b65d3358ab630 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 29 Apr 2024 16:31:15 +0200 Subject: [PATCH] Remove calls to `TestCase::iniSet()` and calls to deprecated methods of `MockBuilder` --- Test/Traits/ValidatorExtensionTrait.php | 4 +- ...teTimeToLocalizedStringTransformerTest.php | 51 +++++++++++++------ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Test/Traits/ValidatorExtensionTrait.php b/Test/Traits/ValidatorExtensionTrait.php index 721371996..70240fc3e 100644 --- a/Test/Traits/ValidatorExtensionTrait.php +++ b/Test/Traits/ValidatorExtensionTrait.php @@ -36,8 +36,8 @@ protected function getValidatorExtension(): ValidatorExtension $this->validator = $this->createMock(ValidatorInterface::class); $metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->onlyMethods(['addPropertyConstraint'])->getMock(); - $this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata)); - $this->validator->expects($this->any())->method('validate')->will($this->returnValue(new ConstraintViolationList())); + $this->validator->expects($this->any())->method('getMetadataFor')->willReturn($metadata); + $this->validator->expects($this->any())->method('validate')->willReturn(new ConstraintViolationList()); return new ValidatorExtension($this->validator, false); } diff --git a/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php b/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php index a29873a26..8a37707e7 100644 --- a/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php +++ b/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php @@ -25,14 +25,17 @@ class DateTimeToLocalizedStringTransformerTest extends BaseDateTimeTransformerTe protected $dateTimeWithoutSeconds; private $defaultLocale; + private $initialTestCaseUseException; + private $initialTestCaseErrorLevel; + protected function setUp(): void { parent::setUp(); // Normalize intl. configuration settings. if (\extension_loaded('intl')) { - $this->iniSet('intl.use_exceptions', 0); - $this->iniSet('intl.error_level', 0); + $this->initialTestCaseUseException = ini_set('intl.use_exceptions', 0); + $this->initialTestCaseErrorLevel = ini_set('intl.error_level', 0); } // Since we test against "de_AT", we need the full implementation @@ -50,6 +53,11 @@ protected function tearDown(): void $this->dateTime = null; $this->dateTimeWithoutSeconds = null; \Locale::setDefault($this->defaultLocale); + + if (\extension_loaded('intl')) { + ini_set('intl.use_exceptions', $this->initialTestCaseUseException); + ini_set('intl.error_level', $this->initialTestCaseUseException); + } } public static function dataProvider() @@ -339,11 +347,15 @@ public function testReverseTransformWrapsIntlErrorsWithErrorLevel() $this->markTestSkipped('intl extension is not loaded'); } - $this->iniSet('intl.error_level', \E_WARNING); + $errorLevel = ini_set('intl.error_level', \E_WARNING); - $this->expectException(TransformationFailedException::class); - $transformer = new DateTimeToLocalizedStringTransformer(); - $transformer->reverseTransform('12345'); + try { + $this->expectException(TransformationFailedException::class); + $transformer = new DateTimeToLocalizedStringTransformer(); + $transformer->reverseTransform('12345'); + } finally { + ini_set('intl.error_level', $errorLevel); + } } public function testReverseTransformWrapsIntlErrorsWithExceptions() @@ -352,11 +364,15 @@ public function testReverseTransformWrapsIntlErrorsWithExceptions() $this->markTestSkipped('intl extension is not loaded'); } - $this->iniSet('intl.use_exceptions', 1); + $initialUseExceptions = ini_set('intl.use_exceptions', 1); - $this->expectException(TransformationFailedException::class); - $transformer = new DateTimeToLocalizedStringTransformer(); - $transformer->reverseTransform('12345'); + try { + $this->expectException(TransformationFailedException::class); + $transformer = new DateTimeToLocalizedStringTransformer(); + $transformer->reverseTransform('12345'); + } finally { + ini_set('intl.use_exceptions', $initialUseExceptions); + } } public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel() @@ -365,12 +381,17 @@ public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel() $this->markTestSkipped('intl extension is not loaded'); } - $this->iniSet('intl.use_exceptions', 1); - $this->iniSet('intl.error_level', \E_WARNING); + $initialUseExceptions = ini_set('intl.use_exceptions', 1); + $initialErrorLevel = ini_set('intl.error_level', \E_WARNING); - $this->expectException(TransformationFailedException::class); - $transformer = new DateTimeToLocalizedStringTransformer(); - $transformer->reverseTransform('12345'); + try { + $this->expectException(TransformationFailedException::class); + $transformer = new DateTimeToLocalizedStringTransformer(); + $transformer->reverseTransform('12345'); + } finally { + ini_set('intl.use_exceptions', $initialUseExceptions); + ini_set('intl.error_level', $initialErrorLevel); + } } protected function createDateTimeTransformer(?string $inputTimezone = null, ?string $outputTimezone = null): BaseDateTimeTransformer