You are here

protected function PHPUnit_Framework_TestCase::setLocale in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/TestCase.php \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

int $category:

string $locale:

Throws

PHPUnit_Framework_Exception

File

vendor/phpunit/phpunit/src/Framework/TestCase.php, line 1229

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.');
  }
}