$value) { $backup_needed = ! array_key_exists($option, $this->_environment_backup); // Handle changing superglobals if (in_array($option, array('_GET', '_POST', '_SERVER', '_FILES'))) { // For some reason we need to do this in order to change the superglobals global $$option; if ($backup_needed) { $this->_environment_backup[$option] = $$option; } // PHPUnit makes a backup of superglobals automatically $$option = $value; } // If this is a static property i.e. Html::$windowed_urls elseif (strpos($option, '::$') !== FALSE) { list($class, $var) = explode('::$', $option, 2); $class = new ReflectionClass($class); if ($backup_needed) { $this->_environment_backup[$option] = $class->getStaticPropertyValue($var); } $class->setStaticPropertyValue($var, $value); } // If this is an environment variable elseif (preg_match('/^[A-Z_-]+$/', $option) OR isset($_SERVER[$option])) { if ($backup_needed) { $this->_environment_backup[$option] = isset($_SERVER[$option]) ? $_SERVER[$option] : ''; } $_SERVER[$option] = $value; } // Else we assume this is a config option else { if ($backup_needed) { $this->_environment_backup[$option] = Kohana::$config->load($option); } list($group, $var) = explode('.', $option, 2); Kohana::$config->load($group)->set($var, $value); } } } /** * Restores the environment to the original state * * @chainable * @return Kohana_Unittest_Helpers $this */ public function restore_environment() { $this->set_environment($this->_environment_backup); } }