Problem/Motivation
In the past, if we wanted to test the behavior of a hook function, then we needed to implement that hook inside of a "test module." Test modules are typically located in core/modules/*/tests/modules/ directories.
#3502432: Make hook testing with kernel tests very simple provided an alternative to creating test modules for Kernel tests. Now hooks may be created as functions directly in Kernel test classes. This reduces the amount of boilerplate necessary for testing hooks, couples the hook function tightly with its related test, and gives us an opportunity to remove some test modules from Core.
The CkeditorTestHooks class (core/modules/ckeditor5/tests/modules/ckeditor_test/src/Hook/CkeditorTestHooks.php) has a hook function that appears to only be used by a Kernel test. Move the hook function into its related test.
See the following for helpful information on making this change:
- The change record about Kernel test hooks
- #3502432: Make hook testing with kernel tests very simple
- This commit contains an example of a moved hook function from a similar issue
Proposed resolution
- Search for the test class or classes that use the ckeditor_test module using any method you prefer, for example grep or an IDE's search.
- Verify that the hook is only used by one or more Kernel tests. Comment if you believe this is not true.
- Copy the hook function from the test module into the Kernel test class(es).
- Delete the hook function. If the Hook class is empty, delete the entire class. If the test module has no other code, delete the entire module.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3581541
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:
- 3581541-move-hooks-from
compare
- main
changes, plain diff MR !15250
Comments
Comment #4
sapnil_biswas commentedmoved the hooks to kernel, marking this for review please let me know if there is requirement of any further changes
Comment #5
dcam commentedI've left a couple of comments on the merge request. They have suggestions for reverting some changes that were made in your PHPCS commit that are unrelated to the work of this issue.
If you aren't aware, we try to avoid unrelated changes in merge requests. By doing this we help prevent unnecessary rebases for ourselves and others. It also reduces the cognitive load for reviewing so no one has to wonder "Why was this change made and is it important?" This issue is a good example. Instead of very quickly reviewing the MR last night I had to go track down the commit where the changes were made, then verify that they aren't necessary.
There are days when I might let one or two minor things like this slide, but I would rather use this as an opportunity to educate. Also, you should check the options you're using for running PHPCS. I tried it on my local environment and it did not attempt to alter those lines. It's probably as simple as copying
core/phpcs.xml.distto your project root.I'm setting the status to Needs Work for the noted changes to be reverted.
Comment #6
sapnil_biswas commented@dcam Thank you sir for your valuable advice this will really help me a ton in my upcoming contributions
Comment #7
dcam commentedThank you for considering my feedback.
The hook was copied accurately from the former class to the test.
The test passes on GitLab and on my local environment.
The ckeditor_test module has been deleted.
I grepped Core for the string "ckeditor_test". There are no remaining instances.
The new @see annotations reference the correct functions.
It looks good to me.
Comment #8
dcam commentedComment #9
catchCommitted/pushed to main and 11.x, thanks!