Replace \Drupal:: with $this->container->get() in test classes of simpletest module

Created on 4 January 2016, over 8 years ago
Updated 15 January 2024, 5 months ago

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: Use \Drupal consistently in tests β†’

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

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
SystemΒ  β†’

Last updated 2 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States Mile23 Seattle, WA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024