function RefreshVariablesTrait::refreshVariables

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Test/RefreshVariablesTrait.php \Drupal\Core\Test\RefreshVariablesTrait::refreshVariables()
  2. 10 core/lib/Drupal/Core/Test/RefreshVariablesTrait.php \Drupal\Core\Test\RefreshVariablesTrait::refreshVariables()
  3. 9 core/lib/Drupal/Core/Test/RefreshVariablesTrait.php \Drupal\Core\Test\RefreshVariablesTrait::refreshVariables()
  4. 8.9.x core/lib/Drupal/Core/Test/RefreshVariablesTrait.php \Drupal\Core\Test\RefreshVariablesTrait::refreshVariables()

Refreshes in-memory configuration and state information.

Useful after a page request is made that changes configuration or state in a different thread.

In other words calling a settings page with $this->submitForm() with a changed value would update configuration to reflect that change, but in the thread that made the call (thread running the test) the changed values would not be picked up.

This method clears the cache and loads a fresh copy.

10 calls to RefreshVariablesTrait::refreshVariables()
LanguageNegotiationInfoTest::keysValuesSet in core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php
Sets key/value pairs for language_test module.
MediaOverviewPageTest::testMediaOverviewPage in core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
Tests that the Media overview page (/admin/content/media).
MediaResourceTestBase::uploadFile in core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php
Tests the 'file_upload' REST resource plugin.
NodeResourceTestBase::testPatchPath in core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php
Tests PATCHing a node's path with and without 'create url aliases'.
ResourceTestBase::refreshTestStateAfterRestConfigChange in core/modules/rest/tests/src/Functional/ResourceTestBase.php
Refreshes the state of the tester to be in sync with the testee.

... See full list

1 method overrides RefreshVariablesTrait::refreshVariables()
StandardPerformanceTest::refreshVariables in core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php
Provides an empty implementation to prevent the resetting of caches.

File

core/lib/Drupal/Core/Test/RefreshVariablesTrait.php, line 25

Class

RefreshVariablesTrait
Provides a method to refresh in-memory configuration and state information.

Namespace

Drupal\Core\Test

Code

protected function refreshVariables() {
  // Clear the tag cache.
  \Drupal::service('cache_tags.invalidator')->resetChecksums();
  foreach (Cache::getBins() as $backend) {
    if (is_callable([
      $backend,
      'reset',
    ])) {
      $backend->reset();
    }
  }
  foreach (Cache::getMemoryBins() as $backend) {
    if (is_callable([
      $backend,
      'reset',
    ])) {
      $backend->reset();
    }
  }
  \Drupal::service('config.factory')->reset();
  \Drupal::service('state')->reset();
  \Drupal::service('entity.memory_cache')->deleteAll();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.