Skip to content

Commit

Permalink
- Add TestCase::setLocale().
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 21, 2007
1 parent a637caf commit 530ec6f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions 3.1/PHPUnit/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple
*/
private $iniSettings = array();

/**
* @var Array
* @access private
*/
private $locale = array();

/**
* @var Array
* @access private
Expand Down Expand Up @@ -320,6 +326,11 @@ public function runBare()
ini_set($varName, $oldValue);
}

// Clean up locale settings.
foreach ($this->locale as $category => $locale) {
setlocale($category, $locale);
}

$this->iniSettings = array();

// Workaround for missing "finally".
Expand Down Expand Up @@ -404,6 +415,31 @@ protected function iniSet($varName, $newValue)
}
}

/**
* This method is a wrapper for the setlocate() function that automatically
* resets the locale to its original value after the test is run.
*
* @param integer $category
* @param string $locale
* @throws InvalidArgumentException
* @throws RuntimeException
* @access protected
* @since Method available since Release 3.1.0
*/
protected function setLocale($category, $locale)
{
if (!in_array($category, array(LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, LC_MESSAGES))) {
throw new InvalidArgumentException;
}

if (!is_array($locale) && !is_string($locale)) {
throw new InvalidArgumentException;
}

$this->locale[$category] = setlocale($category, NULL);
setlocale($category, $locale);
}

/**
* Returns a mock object for the specified class.
*
Expand Down

0 comments on commit 530ec6f

Please sign in to comment.