Issue #3582946: Make tool compatible with Drupal 12

Closes #3582946.

The bot MR (!94) only adds ^12 to the info files. The Drupal 12 pipeline on this MR found what else is needed.

  • Info files: ^12 added to all five, including tool_invalid_test, which !94 misses.
  • PHPUnit 12: Drupal 12 ships PHPUnit 12.5, which no longer reads docblock metadata. 68 test classes had @group, @coversDefaultClass or @covers only in docblocks. They now have the matching attributes too. Traits get #[CoversTrait]: PHPUnit 12 doesn't resolve a trait given to #[CoversClass].
  • Separate processes: Drupal 12 throws for Kernel and Functional tests without #[RunTestsInSeparateProcesses]. The two tool_explorer Functional tests were missing it.
  • execute(): Drupal 12 adds ?object $object = NULL to ExecutableInterface::execute(). ToolPluginBase in tool_ai_connector now takes it, which also works on Drupal 11.
  • PHP 8.5: ReflectionProperty::setAccessible() is deprecated, and a no-op since 8.1. Dropped from ValueViolationsTrait.
  • expectDeprecation(): Drupal 12 removes it. expectUserDeprecationMessage() doesn't exist in PHPUnit 9 (Drupal 10) and doesn't see deprecations on Drupal 11.3. The new ExpectTriggeredDeprecationTrait calls whichever works.
  • Drush 14: restoreState() is gone. DrushCommandTestBase uses setInput() and setOutput(), which Drush 13 has too.
  • CI: the Drupal 12 jobs are on and run on pushes and MRs, the same as the previous major. ai and ai_agents are on the lenient allow list for them, because these dev dependencies don't allow Drupal 12 yet.

The @group and @dataProvider docblocks stay: Drupal 10 still runs PHPUnit 9, which only reads docblocks, and its test discovery skips a class without @group. The @covers docblocks go, now that the attributes carry them. They made PHPUnit 11 report a "Metadata found in doc-comment" deprecation for each test.

Side effect: PHPUnit 11 ignores docblock metadata on a class or method that has attributes. So 885 of the 1298 tests were in no group, and --group tool missed them. Now every test is in a group.

Left for later

  • Whitespace datetime: PHP 8.5 rejects ' ' as a date; PHP 8.3 reads it as "now". So InputCoercionMatrixTest's "whitespace never read as now for datetime" passes on Drupal 11 only because PHP takes the whitespace as a valid date, and fails on Drupal 12. Rejecting whitespace for datetime inputs on every PHP version would fix it, but that changes behavior.
  • Return types: on Drupal 12 core reports that it might add native return types to methods tool overrides (create(): static, getConstraints(): array, setRequired(): static and more). Adding them to public, non-final methods can break subclasses.
  • tool_test.module: Drupal 12 deprecates procedural hook code; its one hook should become a #[Hook] class.
  • Drush 14 deprecates DrushCommands-style commands in favor of Console commands.
  • tool_ai_connector fatals on Drupal 12 until the ai module itself is compatible.
  • Choice objects in addConstraint(): Drupal 12 types DataDefinition::addConstraint() as ?array $options, so passing a Choice object from hook_tool_info_alter() (ChoiceConstraintObjectTest) no longer works. Keeping it means overriding addConstraint() in tool's definition classes.

Testing

  • --list-tests lists the same 1298 tests before and after. Every test now sits in tool, tool_ai_connector, tool_explorer or legacy.
  • All 139 #[Covers*] targets resolve to an existing class, trait or method.
  • Full suite on Drupal 11.3: all 1298 tests pass except EntityInputTypeCheckTest::testDeclaredConstraintsAreChecked, which fails the same way on 1.0.x. No PHPUnit deprecations are left. The tests touched by the follow-up fixes pass on 11.3 too.
  • phpcs with coder 8.3.31: clean.

This code was mainly generated by an AI with my guidance, I reviewed, tested, and refined it.

Edited by Fons Vandamme

Merge request reports

Loading
Loading