Problem/Motivation

After #1411074: Allow kernel tests to share the test environment, we need to complete the adoption of the new #[ShareEnvironment] attribute. Most Kernel tests either work out of the box or require very trivial changes to support the "shared environment" mode, so it might be possible to handle everything here.

Proposed resolution

Add the #[ShareEnvironment] attribute to all core Kernel tests. Opt out via #[ShareEnvironment(FALSE)] any Kernel test requiring a non-trivial conversion to enable the "shared environment" mode. Add a PHPStan check preventing new Kernel tests from being added without the attribute.

This allows to eventually flip the default behavior to "shared environment" mode, when the attribute is missing, without messing up core tests. Contrib Kernel tests would notice this early if enabled on the next major branch.

Remaining tasks

  • Validate the proposed solution
  • Post a MR
  • Reviews

Release notes snippet

All core Kernel tests now feature the #[ShareEnvironment] attribute.

Issue fork drupal-3623409

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

plach created an issue. See original summary.

plach’s picture

catch’s picture

Title: [PP-1] Add the "ShareEnvironment" attribute to all Kernel tests » Add the "ShareEnvironment" attribute to all Kernel tests
Status: Postponed » Needs work
plach’s picture

Status: Needs work » Needs review

This should be ready for review: the MR adds the ShareEnvironment attribute to all Kernel tests, setting to FALSE any test requiring anything more than the trivial conversion. These will have to be handled in follow-ups. The MR adds a PHPStan check preventing new Kernel tests from being added without the attribute.

The preliminary work is isolated in the first three commits, then there is the (uninteresting) big bang commit, which only performs trivial conversions and opt-outs.

plach’s picture

Issue summary: View changes
plach’s picture

I performed a (clean) rebased on top of #3613347: Re-use container in kernel tests. The PHPStan check initially failed because of two new Kernel tests (→ it works), and and a few more tests started failing due to container sharing, so I opted those out. We should be ready for review now.

plach’s picture

Review addressed.