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

Issue fork drupal-3482173

Command icon 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

nicxvan created an issue. See original summary.

nicxvan’s picture

Issue summary: View changes

This is due to a rector bug, so removed noise.

nicxvan’s picture

Ok 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.

nicxvan’s picture

Modules 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.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Some 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

  /**
   * Implements hook_ENTITY_TYPE_insert().
   */
  #[Hook('entity_test_insert')]

This is the original

/**
 * Implements hook_ENTITY_TYPE_insert().
 */
function delay_cache_tags_invalidation_entity_test_insert(EntityTest $entity) {

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.

berdir’s picture

That 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.

nicxvan’s picture

That'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.

nicxvan’s picture

This 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.

nicxvan’s picture

We should be able to add a Rector rule that replaces __FUNCTION__ calls with the static name.

nicxvan’s picture

we 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.

nicxvan’s picture

The 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.

nicxvan’s picture

StatusFileSize
new2.15 KB

Looking 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.

nicxvan’s picture

Issue summary: View changes
StatusFileSize
new1.07 KB
new604 bytes
new1000 bytes
new1.17 KB
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

StatusFileSize
new4.26 KB

core/modules/system/tests/src/Functional/UpdateSystem/RebuildScriptTest.php

This needed the function_exists check to be an implementation check.

nicxvan’s picture

Issue summary: View changes

I'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.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

StatusFileSize
new495 bytes

cspell issue

nicxvan’s picture

I finished converting the rest of the test modules.

nicxvan’s picture

The 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.

nicxvan’s picture

Ok 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.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

StatusFileSize
new2.64 KB

CommonAlterTest patch will likely have conflicts with the new conversion, I'll have to regen it.

nicxvan’s picture

StatusFileSize
new2.64 KB
new1.15 KB

Had to regenerate entity schema and common alter test.

larowlan’s picture

In #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

nicxvan’s picture

I 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.

nicxvan’s picture

Title: Convert all test modules to use OOP Hook implementations. » [ignore] Convert all test modules to use OOP Hook implementations.
Related issues: +#3483599: Convert all procedural hook implementations to Hook classes

Adding ignore here too for now: most work is happening in #3483599: Convert all procedural hook implementations to Hook classes

nicxvan’s picture

Status: Active » Closed (duplicate)