Problem/Motivation
Let's test how the test modules convert.
Fun stats:
285 files
+ 7951
− 7649
https://git.drupalcode.org/project/drupal/-/merge_requests/9896/diffs
Steps to reproduce
Proposed resolution
Follow steps in #3472214: [META] Convert Core hook implementations to Class or method based implementations
./vendor/bin/rector \
--config ./vendor/palantirnet/drupal-rector/rector.php \
process \
core/modules/*/tests \
core/tests
Remaining tasks
Finish reviewing broken tests and attach patches for each.
Most are really minor as you can see.
Tests with separate issues:
#3482618: ModuleHandler->alterDeprecated does not properly handle deprecated OOP hooks
All tests should be fixed
core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php
module_implements_alter needs special consideration.
These are all the same thing:
- core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestXmlAnonTest.php
- core/modules/jsonapi/tests/src/Functional/ConfigTestTest.php
- core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestJsonCookieTest.php
- core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestXmlBasicAuthTest.php
- core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestJsonAnonTest.php
- core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestXmlCookieTest.php
- core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestJsonBasicAuthTest.php
Drupal\Tests\config_test\Functional\Rest\ConfigTestJsonCookieTest::testGet
Drupal\Core\Entity\Exception\AmbiguousEntityClassException: Multiple entity types found for Drupal\config_test\Entity\ConfigTest.
Is syncing functions needed updating.
Tests that need some exceptions to the conversion:
core/tests/Drupal/KernelTests/Core/Extension/ModuleImplementsAlterTest.php
This tests loading of .module, and .inc files, but after conversion the .inc file is deleted, so the function_exists still shows it as not loading.
I think this test module needs to be not converted until .inc modules are deprecated (module_test)
core/modules/system/tests/src/Kernel/Common/AlterTest.php
common_test has a hook implemented on behalf of a theme, this is not supported.
core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php
The .module defining the constant needs to be preserved: core/modules/system/tests/modules/module_autoload_test/module_autoload_test.module
core/modules/system/tests/src/Functional/System/HtaccessTest.php
core/modules/system/tests/fixtures/HtaccessTest/access_test.inc was deleted cause it's empty, but it's required for this test.
Suspected false faliures:
core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
core/modules/block/tests/src/Functional/BlockCacheTest.php
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | EntitySchemaTestHooks.patch | 1.15 KB | nicxvan |
| #32 | Common.AlterTest.patch | 2.64 KB | nicxvan |
| #29 | 0001-fix-_config_test_update_is_syncing_storeConfigRestTest.patch | 4.54 KB | nicxvan |
| #29 | 0002-serviceprovidersContentTranslationTest.patch | 13.61 KB | nicxvan |
| #26 | FileTestHooks.patch | 495 bytes | nicxvan |
Issue fork drupal-3482173
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:
- 3482173-convert-all-test
changes, plain diff MR !9896
- 3482173-testrun2
changes, plain diff MR !9899
Comments
Comment #2
nicxvan commentedThis is due to a rector bug, so removed noise.
Comment #3
nicxvan commentedOk running this against /core/tests hangs, so I ran this against just core/modules manually:
./vendor/bin/rector \
--config ./vendor/palantirnet/drupal-rector/rector.php \
process \
core/modules/announcements_feed/tests/modules \
core/modules/automated_cron/tests/modules \
core/modules/ban/tests/modules \
core/modules/basic_auth/tests/modules \
core/modules/big_pipe/tests/modules \
core/modules/block/tests/modules \
core/modules/block_content/tests/modules \
core/modules/breakpoint/tests/modules \
core/modules/ckeditor5/tests/modules \
core/modules/comment/tests/modules \
core/modules/config/tests/modules \
core/modules/config_translation/tests/modules \
core/modules/contact/tests/modules \
core/modules/content_moderation/tests/modules \
core/modules/content_translation/tests/modules \
core/modules/contextual/tests/modules \
core/modules/datetime/tests/modules \
core/modules/datetime_range/tests/modules \
core/modules/dblog/tests/modules \
core/modules/dynamic_page_cache/tests/modules \
core/modules/editor/tests/modules \
core/modules/field/tests/modules \
core/modules/field_layout/tests/modules \
core/modules/field_ui/tests/modules \
core/modules/file/tests/modules \
core/modules/filter/tests/modules \
core/modules/help/tests/modules \
core/modules/history/tests/modules \
core/modules/image/tests/modules \
core/modules/inline_form_errors/tests/modules \
core/modules/jsonapi/tests/modules \
core/modules/language/tests/modules \
core/modules/layout_builder/tests/modules \
core/modules/layout_discovery/tests/modules \
core/modules/link/tests/modules \
core/modules/locale/tests/modules \
core/modules/media/tests/modules \
core/modules/media_library/tests/modules \
core/modules/menu_link_content/tests/modules \
core/modules/menu_ui/tests/modules \
core/modules/migrate/tests/modules \
core/modules/migrate_drupal/tests/modules \
core/modules/migrate_drupal_ui/tests/modules \
core/modules/mysql/tests/modules \
core/modules/navigation/tests/modules \
core/modules/node/tests/modules \
core/modules/options/tests/modules \
core/modules/page_cache/tests/modules \
core/modules/path/tests/modules \
core/modules/path_alias/tests/modules \
core/modules/pgsql/tests/modules \
core/modules/phpass/tests/modules \
core/modules/responsive_image/tests/modules \
core/modules/rest/tests/modules \
core/modules/sdc/tests/modules \
core/modules/search/tests/modules \
core/modules/serialization/tests/modules \
core/modules/settings_tray/tests/modules \
core/modules/shortcut/tests/modules \
core/modules/sqlite/tests/modules \
core/modules/syslog/tests/modules \
core/modules/system/tests/modules \
core/modules/taxonomy/tests/modules \
core/modules/telephone/tests/modules \
core/modules/text/tests/modules \
core/modules/toolbar/tests/modules \
core/modules/update/tests/modules \
core/modules/user/tests/modules \
core/modules/views/tests/modules \
core/modules/views_ui/tests/modules \
core/modules/workflows/tests/modules \
core/modules/workspaces/tests/modules
To give better history I'm going to commit after each stage.
Comment #4
nicxvan commentedModules that did not convert:
ckeditor5_drupalelementstyle_test
hook_jsonapi_entity_field_field_access
Test modules that do not follow the structure I ran with:
config
dynamic_page_cache
file_module
language
navigation
options
I've deleted the empty .module folders, I'm not rerunning rector right now against the missing test modules.
Comment #6
nicxvan commentedComment #7
nicxvan commentedSome hooks have been renamed incorrectly, that is why there are so many failures.
E.g. looking at the first failure in kernel tests: EndOfTransactionQueriesTest.php
It installs the test module: delay_cache_tags_invalidation
If we look at the hooks there: core/modules/system/tests/modules/delay_cache_tags_invalidation/src/Hook/DelayCacheTagsInvalidationHooks.php
This is the original
So that looks correct.
This test also has entity_test installed
A look at core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php
and core/modules/system/tests/modules/entity_test/src/Hook/EntityTestViewsHooks.php
both look correct too.
Comment #8
berdirThat specific hook has:
> \Drupal::state()->set(__FUNCTION__ . '__pretransaction_foobar', \Drupal::cache()->get('test_cache_pretransaction_foobar'));
I assume the hook is called just fine, but __FUNCTION__ inside the new class is going to have a different value than what it was before.
Comment #9
nicxvan commentedThat's probably it, let's see if converting to __METHOD__ and updating the sets and calls to the new names is enough.
Looks like there are a fair number of other calls to __FUNCTION__ in some new hooks.
I'll work on those if this one failure gets past.
Comment #10
nicxvan commentedThis failed again, I hardcoded the set, why hardcode the value for the test. but not hardcode it for the set in the test?
__FUNCTION__ or __METHOD__ should be the same when called from the same place, this is passing locally so I pushed it up.
Comment #11
nicxvan commentedWe should be able to add a Rector rule that replaces __FUNCTION__ calls with the static name.
Comment #12
nicxvan commentedwe have a script to clean up the module files and .inc files after.
This script only lists the files for deletion.
To perform the actual deletion replace xargs ls with xargs rm in both lines.
The checkout is for an explicit empty file test for now.
find "$1" -name \*.module| xargs grep -LE "^function|^CONST" | xargs ls; git checkout HEAD core/tests/fixtures/empty_file.php.module
find "$1" -name \*.inc| xargs grep -LE "^function|^CONST" | xargs ls
Change the ls to rm when ready.
Comment #14
nicxvan commentedThe script is great.
The __FUNCTION__ handling that was added solved some failures but not all.
I think the ones that remain will be easier to track down.
Comment #15
quietone commentedComment #16
nicxvan commentedLooking through the failures some are due to the test function hooks no longer existing since they are now methods on classes. I fixed the first two obvious ones, after that I stopped being able to reproduce the failures locally.
Edit I figured out why my tests were passing locally.
I'm pushing up to retest. I'm also attaching a patch with the manual fixes I applied.
I'm going to push up a patch to fix each grouping in the pipeline.
Comment #17
nicxvan commentedComment #18
nicxvan commentedComment #19
nicxvan commentedComment #20
nicxvan commentedComment #21
nicxvan commentedComment #22
nicxvan commentedcore/modules/system/tests/src/Functional/UpdateSystem/RebuildScriptTest.php
This needed the function_exists check to be an implementation check.
Comment #23
nicxvan commentedI've finished reviewing all of the failures.
I've created patches for the easy ones.
Several require discussion and follow up issues.
There were a few I could not track down when timeboxed for the review.
There are several test modules not converted because they did not follow the MODULE/test/modules structure, those are noted above.
Comment #24
nicxvan commentedComment #25
nicxvan commentedComment #26
nicxvan commentedcspell issue
Comment #27
nicxvan commentedI finished converting the rest of the test modules.
Comment #28
nicxvan commentedThe patches have not made their way up yet but I think all of the failures but core/modules/system/tests/src/Functional/System/HtaccessTest.php
Have identified fixes.
I still need to test the full conversion and see what failed pop up there. But we're actually getting close.
Comment #29
nicxvan commentedOk I think we've fixed the last of the tests identified here, I'm going to attach the last patches.
Now that we have these, I'm going to reconvert #3483599: Convert all procedural hook implementations to Hook classes then apply these patches and see if anything else needs work.
Comment #30
nicxvan commentedComment #31
nicxvan commentedCommonAlterTest patch will likely have conflicts with the new conversion, I'll have to regen it.
Comment #32
nicxvan commentedHad to regenerate entity schema and common alter test.
Comment #33
larowlanIn #3398525: Add an API for importmaps I tried to use the new OO hook approach for the alter hook I'm using in tests there and found it wasn't being picked up. Could be I was doing something wrong, but ended up going back to a .module file. Would appreciate a second set of eyes if anyone has bandwidth - to save introducing a new one
Comment #34
nicxvan commentedI don't see where you were adding it, was it the one in Core/Assets? it has to be in a module and in the Hooks namespace, if you have a snippet or commit I can look at I will.
Comment #35
nicxvan commentedAdding ignore here too for now: most work is happening in #3483599: Convert all procedural hook implementations to Hook classes
Comment #36
nicxvan commented