+ * Resets service instances in the global instance of MediaWikiServices.
+ *
+ * In contrast to overrideMwServices(), this does not create a new MediaWikiServices instance,
+ * and it preserves any service instances set via setService().
+ *
+ * The primary use case for this method is to allow changes to global configuration variables
+ * to take effect on services that get initialized based on these global configuration
+ * variables. Similarly, it may be necessary to call resetServices() after calling setService(),
+ * so the newly set service gets picked up by any other service definitions that may use it.
+ *
+ * @see MediaWikiServices::resetServiceForTesting.
+ *
+ * @since 1.34
+ */
+ protected function resetServices() {
+ // Reset but don't destroy service instances supplied via setService().
+ foreach ( $this->overriddenServices as $name ) {
+ $this->localServices->resetServiceForTesting( $name, false );
+ }
+
+ // Reset all services with the destroy flag set.
+ // This will not have any effect on services that had already been reset above.
+ foreach ( $this->localServices->getServiceNames() as $name ) {
+ $this->localServices->resetServiceForTesting( $name, true );
+ }
+
+ self::resetGlobalParser();
+ }
+
+ /**
+ * Installs a new global instance of MediaWikiServices, allowing test cases to override
+ * settings and services.
+ *
+ * This method can be used to set up specific services or configuration as a fixture.
+ * It should not be used to reset services in between stages of a test - instead, the test
+ * should either be split, or resetServices() should be used.
+ *
+ * If called with no parameters, this method restores all services to their default state.
+ * This is done automatically before each test to isolate tests from any modification
+ * to settings and services that may have been applied by previous tests.
+ * That means that the effect of calling overrideMwServices() is undone before the next
+ * call to a test method.
+ *
+ * @note Calling this after having called setService() in the same test method (or the
+ * associated setUp) will result in an MWException.
+ * Tests should use either overrideMwServices() or setService(), but not mix both.
+ * Since 1.34, resetServices() is available as an alternative compatible with setService().