Loading
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:
^12added to all five, includingtool_invalid_test, which !94 misses. - PHPUnit 12: Drupal 12 ships PHPUnit 12.5, which no longer reads docblock metadata. 68 test classes had
@group,@coversDefaultClassor@coversonly 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 twotool_explorerFunctional tests were missing it. execute(): Drupal 12 adds?object $object = NULLtoExecutableInterface::execute().ToolPluginBaseintool_ai_connectornow takes it, which also works on Drupal 11.- PHP 8.5:
ReflectionProperty::setAccessible()is deprecated, and a no-op since 8.1. Dropped fromValueViolationsTrait. expectDeprecation(): Drupal 12 removes it.expectUserDeprecationMessage()doesn't exist in PHPUnit 9 (Drupal 10) and doesn't see deprecations on Drupal 11.3. The newExpectTriggeredDeprecationTraitcalls whichever works.- Drush 14:
restoreState()is gone.DrushCommandTestBaseusessetInput()andsetOutput(), which Drush 13 has too. - CI: the Drupal 12 jobs are on and run on pushes and MRs, the same as the previous major.
aiandai_agentsare 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". SoInputCoercionMatrixTest'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(): staticand 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_connectorfatals on Drupal 12 until the ai module itself is compatible.- Choice objects in
addConstraint(): Drupal 12 typesDataDefinition::addConstraint()as?array $options, so passing aChoiceobject fromhook_tool_info_alter()(ChoiceConstraintObjectTest) no longer works. Keeping it means overridingaddConstraint()in tool's definition classes.
Testing
--list-testslists the same 1298 tests before and after. Every test now sits intool,tool_ai_connector,tool_explorerorlegacy.- 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