Problem/Motivation
Follow-up to #3547124: Remove system module from kernel tests that don't need it and #3547554: Remove user module from kernel tests that don't need it.
There are various other modules used in kernel tests that are not required. Some of these are because they are already required by the parent class, but others are genuinely not required.
Steps to reproduce
Run this bash script, might take a couple hours to complete. Then review git diff 11.x to see what can be removed and still have passing tests.
#!/bin/bash
for MODULE in core/modules/*; do
MODULE_NAME=$(basename "$MODULE")
while IFS= read -r FILE; do
if grep -q "^ '$MODULE_NAME',\$" "$FILE"; then
sed -i "/^ '$MODULE_NAME',\$/d" "$FILE"
if ! ./vendor/bin/phpunit --stop-on-error --stop-on-fail -c core/phpunit.xml.dist "$FILE" >/dev/null 2>&1; then
git checkout -- "$FILE"
fi
fi
done < <(find core/ -type f -name '*Test.php' | grep -E '/Kernel(/|Tests/)')
done
Proposed resolution
Remaining tasks
It was suggested we could split this in to tests that can have modules removed because they are already installed in a parent class, and tests that don't need the modules installed at all, but since this is a simple bash script there is not enough context to figure that out.
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Issue fork drupal-3554484
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:
- 3554484-unused-modules
changes, plain diff MR !13582
Comments
Comment #3
mstrelan commentedComment #4
danielvezaNice clean up! Only changes are the removal of modules from test classes, and the tests still pass. Happy for this to be RTBC
Comment #5
quietone commentedI applied the diff and then started the script. I tested the first five files and they all passed tests. I then aborted the script. Is there a reason these are not included in the diff? Are there more files that could be included?
Comment #6
mstrelan commentedI think the script needs to be updated to commit after each module, otherwise later modules can reset the file.
Comment #7
mstrelan commentedApologies for that, as per #6 a lot of files were being reverted.
There are two commits worth noting:
$modules, so it's worth checking there is nothing else like that. Ideally tests would fail if that were the case.Comment #8
smustgrave commentedechoing #4 seems like a good cleanup.
Comment #9
quietone commentedThis looks lovely, I do like a cleanup. I found 2 migrate tests that should be change. Sadly, I couldn't make a suggestion, GitLab isn't giving me that option. There are lots of files changed here and I relied heavily on the file name to find ones that may need adjustment. After that I checked about a range of files and most often found that the removed modules were loaded in a parent class. And for those that weren't the change to $modules seemed just obvious.
When the changes are made, I think this can go back to RTBC.
Comment #10
mstrelan commentedPushed two commits for #9, back to RTBC.
Comment #13
quietone commented@mstrelan, thanks
Committed to 11.x and cherry-picked to 11.3.x
Thanks!