Kernel and functional tests should use the \Drupal
discovery class even though $this->container
is also available.
Replace all calls to $this->container->get()
with \Drupal::service()
, in core module kernel and functional test classes.
Use git grep '\Drupal::' core/modules/*/src/Tests/*
to find these. Get a list of files this way: git grep --name-only '\Drupal::' core/modules/*/src/Tests/*
Originally, this issue proposed the exact opposite. After a lot of discussion here and on
🌱
Use \Drupal consistently in tests
Needs work
, it was decided to use \Drupal::service()
consistently.
file issue per module
fix issues
Initially from
#1957142-64: Replace config() with Drupal::config() →
#2001206: Replace drupal_container() with Drupal::service() →
@todo list of issues
#2067007: Replace \Drupal:: with $this->container->get() in test classes of aggregator module →
#2066999: Replace \Drupal:: with $this->container->get() in test classes of system module →
SimpleTest TestBase
-based tests should use the fixture container, rather than relying on the \Drupal
discovery class.
Currently, TestBase
assigns the fixture container to \Drupal
, since a lot of existing code is still not properly injected.
As more of core is injected, it will be more important to use the fixture for tests, so that we can draw a line of isolation between the test runner and the system under test. This will allow for greater latitude in mocking services and filesystems for core.
Replace all calls to \Drupal::
with corresponding $this->container->get()
, in core module test classes.
Use git grep '\Drupal::' core/modules/*/src/Tests/*
to find these. Get a list of files this way: git grep --name-only '\Drupal::' core/modules/*/src/Tests/*
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.