Skip to content
This repository
Browse code

- Add TestCase::setLocale().

  • Loading branch information...
commit 91c2fe2559ca132f801aad496fd7bdcb6ba25ca4 1 parent 9065df1
Sebastian Bergmann authored

Showing 1 changed file with 36 additions and 0 deletions. Show diff stats Hide diff stats

  1. +36 0 PHPUnit/Framework/TestCase.php
36 PHPUnit/Framework/TestCase.php
@@ -157,6 +157,12 @@
157 157 * @var Array
158 158 * @access private
159 159 */
  160 + private $locale = array();
  161 +
  162 + /**
  163 + * @var Array
  164 + * @access private
  165 + */
160 166 private $mockObjects = array();
161 167
162 168 /**
@@ -320,6 +326,11 @@ public function runBare()
320 326 ini_set($varName, $oldValue);
321 327 }
322 328
  329 + // Clean up locale settings.
  330 + foreach ($this->locale as $category => $locale) {
  331 + setlocale($category, $locale);
  332 + }
  333 +
323 334 $this->iniSettings = array();
324 335
325 336 // Workaround for missing "finally".
@@ -405,6 +416,31 @@ protected function iniSet($varName, $newValue)
405 416 }
406 417
407 418 /**
  419 + * This method is a wrapper for the setlocate() function that automatically
  420 + * resets the locale to its original value after the test is run.
  421 + *
  422 + * @param integer $category
  423 + * @param string $locale
  424 + * @throws InvalidArgumentException
  425 + * @throws RuntimeException
  426 + * @access protected
  427 + * @since Method available since Release 3.1.0
  428 + */
  429 + protected function setLocale($category, $locale)
  430 + {
  431 + if (!in_array($category, array(LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, LC_MESSAGES))) {
  432 + throw new InvalidArgumentException;
  433 + }
  434 +
  435 + if (!is_array($locale) && !is_string($locale)) {
  436 + throw new InvalidArgumentException;
  437 + }
  438 +
  439 + $this->locale[$category] = setlocale($category, NULL);
  440 + setlocale($category, $locale);
  441 + }
  442 +
  443 + /**
408 444 * Returns a mock object for the specified class.
409 445 *
410 446 * @param string $className

0 comments on commit 91c2fe2

Please sign in to comment.
Something went wrong with that request. Please try again.