You are here

trait RefreshVariablesTrait in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Test/RefreshVariablesTrait.php \Drupal\Core\Test\RefreshVariablesTrait
  2. 10 core/lib/Drupal/Core/Test/RefreshVariablesTrait.php \Drupal\Core\Test\RefreshVariablesTrait

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

Hierarchy

1 file declares its use of RefreshVariablesTrait
UiHelperTrait.php in core/tests/Drupal/Tests/UiHelperTrait.php

File

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

Namespace

Drupal\Core\Test
View source
trait RefreshVariablesTrait {

  /**
   * 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->drupalPostForm() 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.
   */
  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();
      }
    }
    \Drupal::service('config.factory')
      ->reset();
    \Drupal::service('state')
      ->resetCache();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RefreshVariablesTrait::refreshVariables protected function Refreshes in-memory configuration and state information. 3