diff -u b/core/modules/system/src/Tests/Form/FormCacheTest.php b/core/modules/system/src/Tests/Form/FormCacheTest.php --- b/core/modules/system/src/Tests/Form/FormCacheTest.php +++ b/core/modules/system/src/Tests/Form/FormCacheTest.php @@ -89,8 +89,7 @@ * Tests the form cache without a logged-in user. */ function testNoCacheToken() { - $current_user = $this->container->get('current_user'); - $current_user->setAccount(new AnonymousUserSession()); + \Drupal::service('account_switcher')->switchTo(new AnonymousUserSession()); $this->form_state->set('example', $this->randomMachineName()); \Drupal::formBuilder()->setCache($this->form_build_id, $this->form, $this->form_state);