Problem/Motivation

PHPUnit testing produce the following for Scheduler (which needs to be fixed) and for several third-party modules (which need to be ignored)

{the-module}_requirements without a #[LegacyRequirementsHook] attribute is deprecated in drupal:11.3.0 and removed in drupal:13.0.0. See https://www.drupal.org/node/3549685

Change record: https://www.drupal.org/node/3549685

Issue fork scheduler-3587907

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

jonathan1055 created an issue. See original summary.

jonathan1055 changed the visibility of the branch 2.x to hidden.

jonathan1055’s picture

Title: Add #[LegacyRequirementsHook] attribute » Add #[ LegacyRequirementsHook ] attribute

Starting point using Next Minor on Gitlab Templates default-ref. The phpunit 'scheduler' test group log is 15,401 lines long. There are 125 matches for #[LegacyRequirementsHook] attribute is deprecated but only 25 of those are for Scheduer. There are 20 tests and each test reports 5 deprecations. The other 4 are for address, commerce x2 and token.

jonathan1055’s picture

Using Gitlab Templates 'main' ref the Next Minor phpunit log is 15,364 lines. The saving of only 37 lines is the removal of the TestDiscovery deprecation warnings for 3rd-party modules. The phpunit deprecations for other modules are still shown in the log.

jonathan1055’s picture

There are three types of change linked from the main change record, and https://www.drupal.org/node/3490851 deals with $phase === 'runtime' which is what we have in scheduler_requirements() in scheduler.install. The example is inside a new class FileRequirementsHook in the Drupal\{myproject}\Hook namespace. It is not clear how to do this when the original implementation is in a global function in procedural php in the .install file.

The first linked CR https://www.drupal.org/node/3492429 explains about adding the new class Drupal\{mymodule}\Install\Requirements but this is not the same as the runtime phase.

jonathan1055’s picture

After adding #[LegacyRequirementsHook] in .install (using this core example) the message count has dropped from 125 to 100
https://git.drupalcode.org/project/scheduler/-/jobs/10210896/viewer

Good to see that we get a test failure

 Scheduler Status Report (Drupal\Tests\scheduler\Functional\SchedulerStatusReport)
     ✘ Status report
       ┐
       ├ Behat\Mink\Exception\ResponseTextException: The text "Scheduler Time Check" was not found anywhere in the text of the current page.
       │

as that shows the status message is not be present when the legacy hook is not run on 11.3+

jonathan1055’s picture

StatusFileSize
new184.1 KB
new204.42 KB

After a little trial and error, due to not being able to find any example or help from the CR, I found that src/Hook/SchedulerRequirementsHook.php is the correct file to add. (commit)

Screen grabs showing the original function in use on 11.2 and the new on 11.3

The message test is fixed. Next to remove the 100 deprecation messages for 3rd-party modules.

  • jonathan1055 committed d7fb3cc1 on 2.x
    #3587907 Add #[LegacyRequirementsHook] attribute. Add src/Hook/...
jonathan1055’s picture

Status: Active » Fixed

With this commit to .deprecation-ignore.txt we no longer get the other 100 #[LegacyRequirementsHook] attribute is deprecated messages for the 3rd-party modules. The log is only 11,819 lines

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.