Skip to content

Commit

Permalink
Remove calls to TestCase::iniSet() and calls to deprecated methods …
Browse files Browse the repository at this point in the history
…of `MockBuilder`
  • Loading branch information
alexandre-daubois committed May 6, 2024
1 parent 6e732c4 commit 08c924b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Test/Traits/ValidatorExtensionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 08c924b

Please sign in to comment.