/** * Force a consistent, clean, unmodified state. This should reset * any modified environment back to the way it was before any test * was executed. */ public static function resetState() { // First, clear any buffers so we can display error messages static::bufferReset(); // cwd = where phpunit was executed if (!is_null(self::$preservedCwd)) { chdir(self::$preservedCwd); } else { self::$preservedCwd = getcwd(); } // Stop the session if (session_id() !== "") { session_write_close(); } // libxml can keep errors around - remove them if we had any libxml_clear_errors(); // Clear XML errors // Swap replaced things back to the normal ones if needed self::resetRenamer(); // Set up superglobals, static references, etc self::resetSuperglobals(); // Reset error handlers restore_error_handler(); // Some code sets its own handlers restore_exception_handler(); // We remove them and add our own }
/** * Return to a known good state after tests */ public function tearDown() { $this->resetEnvironment(); PHPToolsTestUtil::resetState(); parent::tearDown(); // PHPUnit }