Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Add TestCase::setLocale().

  • Loading branch information...
commit 91c2fe2559ca132f801aad496fd7bdcb6ba25ca4 1 parent 9065df1
@sebastianbergmann authored
Showing with 36 additions and 0 deletions.
  1. +36 −0 PHPUnit/Framework/TestCase.php
View
36 PHPUnit/Framework/TestCase.php
@@ -157,6 +157,12 @@
* @var Array
* @access private
*/
+ private $locale = array();
+
+ /**
+ * @var Array
+ * @access private
+ */
private $mockObjects = array();
/**
@@ -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".
@@ -405,6 +416,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.
*
* @param string $className
Please sign in to comment.
Something went wrong with that request. Please try again.