Problem/Motivation
Calls to \Drupal::
within core module test classes need to be replace so that they use the $this->container
fixture.
This issue is the child of parent issue: #2066993: [meta] Replace \Drupal:: with $this->container->get() in core test classes
Proposed resolution
Replace \Drupal
with $this->container
in the simpletest module.
How to:
Use this grep to find occurrences of \Drupal within the test classes: git grep '\Drupal::' core/modules/simpletest/src/Tests/*
Add --name-only to find files: git grep --name-only '\Drupal::' core/modules/simpletest/src/Tests/*
Replace these usages of \Drupal with $this->container, except for some very special cases for the simpletest module.
In many instances, it's possible to get a reference to a service and then use it multiple times within a test method. This is preferable to calling $this->container
multiple times.
Do not turn the services into class properties of the test class. Access them within the test method only.
Run tests for your module locally to make sure they work and pass. You can use the Testing/Simpletest UI within the installed site, or use ./core/scripts/run-tests.sh, like this: php ./core/scripts/run-tests.sh simpletest