Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294483

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

$
0
0

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

Remaining tasks

User interface changes

API changes

Data model changes


Viewing all articles
Browse latest Browse all 294483

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>