Add return types to CookieResourceTestTrait

Created on 16 June 2025, 28 days ago

Problem/Motivation

Child issue of πŸ“Œ Determine if there are other TestTraits we can add return types to. Active . Adding void return types to 3 functions removes 1746 lines from the baseline.

As per discussion on the parent issue we need to determine if this trait is used in a base class. If it is, then adding return types may result in a BC break for child classes that override methods from the trait. There are 97 usages of use CookieResourceTestTrait in core, and they are all in files that end in Test.php and none are in files that end in TestBase.php. This is a good start.

We also need to look at whether returning void from the method is indeed the intended outcome:

  • All 28 usages of initAuthentication are in the form of $this->initAuthentication();, there are no usages that assign the result to a variable or use the result in some way.
  • Same for the 4 usages of assertResponseWhenMissingAuthentication
  • Same of the 3 usages of assertAuthenticationEdgeCases. The interesting thing to highlight here is the last line sets a value in the $request_options array that is neither passed by reference nor returned. This seems to be a mistake.

Furthermore, these 3 methods are documented in \Drupal\Tests\rest\Functional\ResourceTestBase and don't indicate that they should have a return value. Adding a return type declaration to the test base would be more likely to introduce a BC break.

The other place to look is contrib. This search seems to find usages while filtering out duplication of core and contrib modules - https://git.drupalcode.org/search?group_id=2&scope=blobs&search=%22use+C...

Note there is at least one abstract class there - https://git.drupalcode.org/project/drupal_admin_ui/-/blob/master/admin_u... but the child class in the same namespace doesn't override any of these methods, so again we're likely safe.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

rest.module

Created by

πŸ‡¦πŸ‡ΊAustralia mstrelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024