Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Test/RefreshVariablesTrait.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
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 } |