Problem/Motivation

Follow-up from #3613347: Re-use container in kernel tests and #1411074: Allow kernel tests to share the test environment.

We are moving towards kernel tests sharing a database/environment between methods by default, with environment-per-method as opt in.

We added a performance optimisation a long time ago to use a memory key/value in kernel tests, however a shared database requires the key/value store to use the regular database storage.

The combined performance gain of those two issues is approaching a 50% speed-up in some tests, so we can simplify things by always using the database key/value store and removing the special handling in kernel tests, which simplifies things a bit too.

#3613347: Re-use container in kernel tests does that but leaves the $keyValue property intact, in this issue, we should deprecate the property, update any tests that rely on it, and add a change record for contributed modules.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3629287

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

catch created an issue. See original summary.

sapnil_biswas’s picture

Assigned: Unassigned » sapnil_biswas

Getting started on this

longwave’s picture

Status: Active » Needs work
Issue tags: +Needs change record

The MR looks good but we need a change record, then point the deprecation to the change record instead of this issue.

sapnil_biswas’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Created the change record at change record #3629745 and updated the deprecation message and test coverage to reference it.

sapnil_biswas’s picture

Assigned: sapnil_biswas » Unassigned
catch’s picture

This is used less than I would have expected.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

sapnil_biswas’s picture

Status: Needs work » Needs review
Issue tags: +no-needs-review-bot
abryantdev’s picture

Reviewed MR !17396 on current main (the patch applies cleanly), PHP 8.5.12, SQLite.

KernelTestBaseTest passes (19 tests, 51 assertions), including the new testGetKeyValuePropertyDeprecation.
WorkspaceFormPersistenceTest passes (1 test, 14 assertions).

One side effect to consider. KernelTestBase::__get() returns NULL for every property name other than keyValue. On main, reading an undefined property in a kernel test raises PHP's "Undefined property" warning. With this MR it is silent. I checked with a scratch kernel test that does assertNull($this->typoedProperty): on main it reports 1 warning ("Undefined property: ...::$typoedProperty"), with the MR it passes with no warning. A typo in a property name in any kernel test, or in contrib, would stop being reported.

Suggestion: after the keyValue branch, trigger an E_USER_WARNING with the same text PHP uses, for example sprintf('Undefined property: %s::$%s', static::class, $name), then return NULL. That keeps the deprecation and keeps the old warning for everything else.

I did not change the issue status.

AI use: an AI assistant set up and ran these tests and drafted this comment. I reviewed the results before posting.