Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Test / RefreshVariablesTrait.php
1 <?php
2
3 namespace Drupal\Core\Test;
4
5 use Drupal\Core\Cache\Cache;
6
7 /**
8  * Provides a method to refresh in-memory configuration and state information.
9  */
10 trait RefreshVariablesTrait {
11
12   /**
13    * Refreshes in-memory configuration and state information.
14    *
15    * Useful after a page request is made that changes configuration or state in
16    * a different thread.
17    *
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.
22    *
23    * This method clears the cache and loads a fresh copy.
24    */
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'])) {
30         $backend->reset();
31       }
32     }
33
34     \Drupal::service('config.factory')->reset();
35     \Drupal::service('state')->resetCache();
36   }
37
38 }