Problem/Motivation
#3502432: Make hook testing with kernel tests very simple made it possible to implement hook methods inside Kernel test classes, so that test hooks did not need to be implemented in separate modules. This generally works for most cases.
However, when alter hooks are implemented, and there multiple related types of alter hooks invoked (such as form_alter, form_FORM_ID_alter, etc.), and there are methods implementing multiple of these types, the the kernel test class hook implementations are not executed.
This occurs because in ModuleHandler::getCombinedListeners(), as part of the process of ordering all the related hook implementations, the implementations are filtered by installed modules. Since the "module" that is defined for Kernel test hook implementations is core, the kernel hook implementations are filtered out.
Steps to reproduce
See test class in MR 15493 for an example of a kernel test class that has implements multiple "types" of the same basic hook.
Proposed resolution
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3585498
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
Comment #3
godotislateMR: https://git.drupalcode.org/project/drupal/-/merge_requests/15493
Failing test only job: https://git.drupalcode.org/project/drupal/-/jobs/9411523
Comment #4
nicxvan commentedGood find, I wonder if it's better to add
corehere$modules = array_intersect(array_keys($this->moduleList), $modules);so it's not lost in the intersect.It's closer to what we did in
getHookImplementationListand doesn't require tracking core for every alter just to handle Kernel tests.Comment #5
godotislateA lot of tests failed when I just added core to modules in the MR where I first ran into this: https://git.drupalcode.org/project/drupal/-/commit/6ac38e8e675a23e9a8c30...
I do have another idea I can try.
Comment #6
nicxvan commentedYeah I think it would have to be in the array intersect on the left side.
Comment #7
godotislateOK, this might be close to what you were asking.
Test only still fails as expected: https://git.drupalcode.org/project/drupal/-/jobs/9414907
Comment #8
nicxvan commentedYes that is it exactly!
Comment #9
nicxvan commentedThe comment doesn't exactly make sense anymore though so it could use an update. Something about adding core so if there is a kernel hook alter it will be returned.
Comment #10
godotislateDid my best to reword it.
Comment #11
nicxvan commentedThank you!
Last change was just the comment, the previous run had the test only failure. I think this is ready!
I'm not sure why this was tagged needs review queue initiative, my understanding was that tag means it was reviewed as part of that initiative which this hasn't been.
Comment #12
alexpottNeeds to implemented for 11.x - there are conflicts that look tricky to resolve.
Comment #15
alexpottDid the merge conflict resolution myself.
Comment #16
alexpottCommitted and pushed 849bda6a8e9 to 11.x and 1400d62c528 to 11.3.x. Thanks!