(see also #3369958: Improve unit test coverage for ModuleHandler)
Problem/Motivation
The hook system is currently covered directly by Drupal\Tests\Core\Extension\ModuleHandlerTest, and indirectly by various module tests that use hooks.
There are some shortcomings with this, which become apparent when we try to refactor the hook system, as in #3368812: Hux-style hooks, proof of concept.
- The coverage is insufficient: There are some bugs we can introduce that do not cause test fails in ModuleHandlerTest.
- As a unit test, this one covers the class itself, instead of the "hook system". Currently this is mostly the same, but if we refactor it, the "hook system" will be a combination of classes, and their wiring as services.
- The test relies heavily on mocking, including mocking of protected methods in ModuleHandler.
- As a consequence, refactoring the hook system would require big changes in the ModuleHandlerTest, which makes it a poor solution for verifying that existing hooks still work as expected.
In #3369958: Improve unit test coverage for ModuleHandler I propose changes to the Drupal\Tests\Core\Extension\ModuleHandlerTest.
But this does not change the main problem: As a unit test, the test covers specific classes, instead of the system in its real-world composition.
Steps to reproduce
See #3368812: Hux-style hooks, proof of concept how many changes are needed in ModuleHandlerTest, as a consequence of the refactoring.
Proposed resolution
Add a kernel test to cover the hook system.
Remaining tasks
Is there anything in #7 to do?
Do no add a new word to dictionary.txt
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3381785
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
donquixote commentedThe kernel tests are based on the unit tests in #3369958: Improve unit test coverage for ModuleHandler.
Some methods are not converted yet.
I already tested how the test will change with the Hux MR.
Most of it remains unchanged, because we don't rely on mocks, and we use the real service definitions, instead of custom composition.
Comment #4
donquixote commentedThere is one commit borrowed from #3379488: Add kernel tests for event system.
Comment #5
donquixote commentedMaybe we can drop some parts of
Drupal\Tests\Core\Extension\ModuleHandlerTest?Not sure.
Comment #6
donquixote commentedComment #7
donquixote commentedThis MR introduces other changes:
This works, but needs to be cleaned up a bit and made universally usable by all tests.
It would be interesting to have virtual modules in stream wrappers.
To do this we need to allow modules to have a different root path.
Comment #8
donquixote commentedComment #9
smustgrave commentedWas hoping #3381933: Establish "core/tests/$type" as a canonical place for test extensions would land first but I'll go ahead and mark this. If this lands before guess the other could be closed.
Comment #10
quietone commentedI'm triaging RTBC issues. I read the IS, the comments and the MR (not a code review).
Always good to improve testing, thanks!
Comment #7 states "This works, but needs to be cleaned up a bit and made universally usable by all tests." It seems this should be at needs work?
I left some comments in the MR, mostly about comments. However, I see that this is adding a word to the dictionary. We should not be doing that and I have asked a question about that. Because of that, and possibly #7, I am setting this back to needs work.
Comment #11
nicxvan commentedDo we still need this? There are now kernel tests for hooks.
Comment #13
nicxvan commentedWe have since gotten these tests in.
The core test scanner has its own issue linked.
This also has an attribute for installing modules, I'm not sure that is necessary.
I've applied credit.