diff --git a/ChangeLog-12.0.md b/ChangeLog-12.0.md index 0023d08bd10..74aa5c5af7c 100644 --- a/ChangeLog-12.0.md +++ b/ChangeLog-12.0.md @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 12.0 release series are documented in this fi ### Removed * [#5215](https://github.com/sebastianbergmann/phpunit/issues/5215): `TestCase::iniSet()` +* [#5217](https://github.com/sebastianbergmann/phpunit/issues/5217): `TestCase::setLocale()` * [#5246](https://github.com/sebastianbergmann/phpunit/issues/5246): `TestCase::createTestProxy()` * [#5247](https://github.com/sebastianbergmann/phpunit/issues/5247): `TestCase::getMockForAbstractClass()` * [#5248](https://github.com/sebastianbergmann/phpunit/issues/5248): `TestCase::getMockFromWsdl()` diff --git a/DEPRECATIONS.md b/DEPRECATIONS.md index 6d93b95eac0..e0ce95cbc48 100644 --- a/DEPRECATIONS.md +++ b/DEPRECATIONS.md @@ -47,7 +47,6 @@ This functionality is currently [hard-deprecated](https://phpunit.de/backward-co | Issue | Description | Since | Replacement | |-------------------------------------------------------------------|-------------------------------------------------------------|--------|-----------------------------------------------------------------------------------------| | [#4505](https://github.com/sebastianbergmann/phpunit/issues/4505) | Metadata in doc-comments | 10.3.0 | Metadata in attributes | -| [#5216](https://github.com/sebastianbergmann/phpunit/issues/5216) | `TestCase::setLocale()` | 10.3.0 | | | [#5800](https://github.com/sebastianbergmann/phpunit/issues/5800) | Targeting traits with `#[CoversClass]` and `#[UsesClass]` | 11.2.0 | `#[CoversClass]` and `#[UsesClass]` also target the traits used by the targeted classes | | [#5951](https://github.com/sebastianbergmann/phpunit/issues/5951) | `includeUncoveredFiles` configuration option | 11.4.0 | | | [#5958](https://github.com/sebastianbergmann/phpunit/issues/5958) | `#[CoversTrait]` and `#[UsesTrait]` attributes | 11.4.0 | `#[CoversClass]` and `#[UsesClass]` also target the traits used by the targeted classes | diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 65e58f5e17d..793dd04abd2 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -9,12 +9,6 @@ */ namespace PHPUnit\Framework; -use const LC_ALL; -use const LC_COLLATE; -use const LC_CTYPE; -use const LC_MONETARY; -use const LC_NUMERIC; -use const LC_TIME; use const PHP_EOL; use function array_keys; use function array_merge; @@ -48,7 +42,6 @@ use function restore_exception_handler; use function set_error_handler; use function set_exception_handler; -use function setlocale; use function sprintf; use function str_contains; use function trim; @@ -111,8 +104,7 @@ */ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, Test { - private const LOCALE_CATEGORIES = [LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME]; - private ?bool $backupGlobals = null; + private ?bool $backupGlobals = null; /** * @var list @@ -175,11 +167,6 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T */ private array $dependencyInput = []; - /** - * @var array - */ - private array $locale = []; - /** * @var list */ @@ -639,7 +626,6 @@ final public function runBare(): void $this->restoreGlobalErrorExceptionHandlers(); $this->restoreGlobalState(); $this->unregisterCustomComparators(); - $this->cleanupLocaleSettings(); libxml_clear_errors(); $this->testValueObjectForEvents = null; @@ -1234,50 +1220,6 @@ final protected function runTest(): mixed return $testResult; } - /** - * This method is a wrapper for the setlocale() function that automatically - * resets the locale to its original value after the test is run. - * - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5216 - * - * @codeCoverageIgnore - */ - final protected function setLocale(mixed ...$arguments): void - { - Event\Facade::emitter()->testTriggeredPhpunitDeprecation( - $this->valueObjectForEvents(), - 'setLocale() is deprecated and will be removed in PHPUnit 12 without replacement.', - ); - - if (count($arguments) < 2) { - throw new Exception; - } - - [$category, $locale] = $arguments; - - if (!in_array($category, self::LOCALE_CATEGORIES, true)) { - throw new Exception; - } - - if (!is_array($locale) && !is_string($locale)) { - throw new Exception; - } - - $this->locale[$category] = setlocale($category, '0'); - - $result = setlocale(...$arguments); - - if ($result === false) { - throw new Exception( - 'The locale functionality is not implemented on your platform, ' . - 'the specified locale does not exist or the category name is ' . - 'invalid.', - ); - } - } - /** * Creates a mock object for the specified interface or class. * @@ -1919,15 +1861,6 @@ private function unregisterCustomComparators(): void $this->customComparators = []; } - private function cleanupLocaleSettings(): void - { - foreach ($this->locale as $category => $locale) { - setlocale($category, $locale); - } - - $this->locale = []; - } - /** * @throws Exception */