Skip to content

Commit

Permalink
Closes #5217
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 6, 2024
1 parent 8d269d2 commit 3ad870b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 69 deletions.
1 change: 1 addition & 0 deletions ChangeLog-12.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down
1 change: 0 additions & 1 deletion DEPRECATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
69 changes: 1 addition & 68 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<string>
Expand Down Expand Up @@ -175,11 +167,6 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
*/
private array $dependencyInput = [];

/**
* @var array<int, non-empty-string>
*/
private array $locale = [];

/**
* @var list<MockObjectInternal>
*/
Expand Down Expand Up @@ -639,7 +626,6 @@ final public function runBare(): void
$this->restoreGlobalErrorExceptionHandlers();
$this->restoreGlobalState();
$this->unregisterCustomComparators();
$this->cleanupLocaleSettings();
libxml_clear_errors();

$this->testValueObjectForEvents = null;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 3ad870b

Please sign in to comment.