Updated: Comment #N

Problem/Motivation

I noticed that a number of issues that converted to use services/change drupal_container() to Drupal:: where forced to use $this->container->get(). I don't understand the reason for this. We don't want to test tests, do we?

The DX of $this->container->get('config.factory')->get('something') instead of \Drupal::config('something') is crap, both for remembering how to call it and then not having method autocomplete.

Proposed resolution

Allow and recommend to use \Drupal:: in test methods. (No need to change already converted code, I care about DX when writing new code).

Remaining tasks

Discuss, fight!

User interface changes

Duh.

API changes

None.

Many, for example #2078155-21: Access protected field items being removed.

Comments

dawehner’s picture

#2084637: Use a service container with automated wrappers would really help at least for the autocompletion.

I am fine with using \Drupal, and even don't really care about consistency ... is it safe that \Drupal::getContainer() and $this->container() is the same all the time?

berdir’s picture

No, right now they are not, we sometimes rebuild the container but don't update $this->container. That doesn't affect most code, but it does affect me in #1786490: Add caching to the state system, have to use \Drupal there.

alexpott’s picture

Status: Active » Closed (duplicate)
alexpott’s picture

Issue summary: View changes

Updated issue summary.