3 namespace Drupal\Core\Test;
5 use Drupal\Core\Cache\Cache;
8 * Provides a method to refresh in-memory configuration and state information.
10 trait RefreshVariablesTrait {
13 * Refreshes in-memory configuration and state information.
15 * Useful after a page request is made that changes configuration or state in
18 * In other words calling a settings page with $this->drupalPostForm() with a
19 * changed value would update configuration to reflect that change, but in the
20 * thread that made the call (thread running the test) the changed values
21 * would not be picked up.
23 * This method clears the cache and loads a fresh copy.
25 protected function refreshVariables() {
26 // Clear the tag cache.
27 \Drupal::service('cache_tags.invalidator')->resetChecksums();
28 foreach (Cache::getBins() as $backend) {
29 if (is_callable([$backend, 'reset'])) {
34 \Drupal::service('config.factory')->reset();
35 \Drupal::service('state')->resetCache();