protected function PHPUnit_Framework_TestCase::setLocale

This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.

@since Method available since Release 3.1.0

Parameters

integer $category:

string $locale:

Throws

PHPUnit_Framework_Exception

File

drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php, line 1252

Class

PHPUnit_Framework_TestCase
A TestCase defines the fixture to run multiple tests.

Code

protected function setLocale() {
  $args = func_get_args();
  if (count($args) < 2) {
    throw new PHPUnit_Framework_Exception();
  }
  $category = $args[0];
  $locale = $args[1];
  $categories = array(
    LC_ALL,
    LC_COLLATE,
    LC_CTYPE,
    LC_MONETARY,
    LC_NUMERIC,
    LC_TIME,
  );
  if (defined('LC_MESSAGES')) {
    $categories[] = LC_MESSAGES;
  }
  if (!in_array($category, $categories)) {
    throw new PHPUnit_Framework_Exception();
  }
  if (!is_array($locale) && !is_string($locale)) {
    throw new PHPUnit_Framework_Exception();
  }
  $this->locale[$category] = setlocale($category, NULL);
  $result = call_user_func_array('setlocale', $args);
  if ($result === FALSE) {
    throw new PHPUnit_Framework_Exception('The locale functionality is not implemented on your platform, ' . 'the specified locale does not exist or the category name is ' . 'invalid.');
  }
}