Problem/Motivation
Since #3390193: Add a drupalGet() method to KernelTestBase we can convert functional tests that make simple http requests to kernel tests. This issue is an attempt to find low hanging fruit in the system module.
For this I am experimenting with using Github Copilot chat in PhpStorm with Claude Opus 4.6 model. I guided it to find tests in system module that have drupalGet requests, and worked with it to detect patterns that are too complicated for a first pass. Once it had found candidates it performed the conversion and adjusted setup tasks until the tests passed. Then once it was passing it was instructed to remove as many additional steps as possible to produce a minimal diff while still passing. Finally it committed each one with a commit message that indicates the time reduction.
Here is a summary of the results:
| Test | Before | After | Saved |
|-----------------------------------|---------|--------|---------|
| AdminMetaTagTest | 3.356s | 0.908s | 2.448s |
| ContentNegotiationTest | 3.291s | 1.109s | 2.182s |
| DefaultMetatagsTest | 3.166s | 1.042s | 2.124s |
| DefaultMobileMetaTagsTest | 6.997s | 1.577s | 5.420s |
| ElementsContainerTest | 4.397s | 0.795s | 3.602s |
| EngineNyanCatTest | 4.028s | 0.999s | 3.029s |
| ImageLoadingAttributeTest | 3.858s | 0.780s | 3.078s |
| RenderArrayNonHtmlSubscriberTest | 3.619s | 0.694s | 2.925s |
| ServiceProviderWebTest | 4.287s | 1.104s | 3.183s |
| TimeZoneAbbreviationRouteTest | 46.916s | 8.335s | 38.581s |
| TwigEnvironmentTest | 3.586s | 0.709s | 2.877s |
Total before: 87.501s
Total after: 18.052s
Total time saved: 69.449s
Reduction: 79.4%
The juiciest one here is TimeZoneAbbreviationRouteTest because it was using a data provider. This could be a good pattern to target when finding other tests to convert.
Steps to reproduce
Proposed resolution
Remaining tasks
Postponed on #3582228: add $options and $headers parameters to HttpKernelUiHelperTrait::drupalGet()
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3583587
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:
- 3583587-system-kernel-tests
changes, plain diff MR !15376
Comments
Comment #3
mstrelan commentedComment #4
mstrelan commentedHad to revert ContentNegotiationTest and TimeZoneAbbreviationRouteTest while we wait for #3582228: add $options and $headers parameters to HttpKernelUiHelperTrait::drupalGet(). Could postpone on that or move these to a follow up.
Comment #5
andypostLooks great! curious why some tests require system module installed it may cut more
Comment #6
mstrelan commented@andypost the tests live in system module, so presumably they are testing some functionality from that module, otherwise they should probably be in
core/tests. Each test was run without installing system module, and it was only added in if it was required to make the test pass. FWIW system module is a required module so it is always installed in Functional tests. Changing to Kernel tests means we might need to explicitly install it. Some of the tests require config from system module simply to set the front page route since that's what drupalGet is requesting.Comment #7
dwwRe: #4: I vote move those to a follow-up for once #3582228: add $options and $headers parameters to HttpKernelUiHelperTrait::drupalGet() lands. The rest of this looks great. Might as well get these in ASAP.
Although the
toString()incore/modules/system/tests/src/Kernel/Render/RenderArrayNonHtmlSubscriberTest.phpwouldn't be necessary once #3582228 is committed, either, since that's expanding the Kernel drupalGet() to handle either astringor aUrl$patharg. /shrugComment #8
mstrelan commentedThanks for the review. I'd be happy to postpone on #3582228: add $options and $headers parameters to HttpKernelUiHelperTrait::drupalGet() so we can un-revert those two commits and simplify the tests using toString() and manually implementing xpath. Looks like it's close.
Comment #9
catchMoving back to needs review for #8, do we actually want to postpone this, or open a follow-up for further things once the other issue is in? But I think we should decide before commit.
Comment #10
mstrelan commentedI think postpone, the biggest time saving was reverted and it would be good to restore it, and not have to rework some of the others later.
Comment #11
mstrelan commentedBlocker is in. Restored the reverted commits and removed the additional
toString()calls that are no longer required.Comment #12
dwwThe MR diff looks great once more. Nothing to complain about. Back to RTBC. Thanks!
Comment #13
catchSorry one more question: #3583594: Add getUrl() and (renamed) xpath() helpers to HttpKernelUiHelperTrait is open, I don't think it's a showstopper to commit this without that issue having landed yet, but then can we convert the test that needs it here in that issue?
Otherwise there's no actual test logic changes in here at all, just slightly different setup, which is great.
Comment #14
mstrelan commentedI think the short answer is yes. The xpath stuff is a bit messy due to the naming conflict and I'd rather not wait for it. Would prefer to exclude that test from this issue, is that what you are suggesting too?
Comment #15
catchI think we could probably go ahead here but make a note to update it again in that issue?
Comment #16
mstrelan commentedDone, added to the remaining tasks of the other issue.
Comment #20
catchCommitted/pushed to main and 11.x, thanks!