[PHPUnit 10] Provide a static alternative to randomMachineName() and implement in data providers

Created on 12 April 2023, over 1 year ago
Updated 4 May 2023, over 1 year ago

Problem/Motivation

PHPUnit 10 deprecates use of non-static @dataProvider methods. This means that @dataProvider methods can no longer make calls to non-static methods. Any non-static call ($this->someMethod()) needs to be replaced by a call to a static alternative (static::someOtherMethod()), that would have to be implemented if not available.

In this issue, focus on replacing $this->randomMachineName()

Proposed resolution

Essentially:

  • Introduce a new abstract static class \Drupal\TestTools\Random that copies the methods from Drupal\Tests\RandomGeneratorTrait, but changes them to static
  • Make Drupal\Tests\RandomGeneratorTrait::random*() and Drupal\Tests\UnitTestCase::random* methods become proxies to the new statict methods, so we can keep BC for tests
  • Convert usage of $this->random*() in data providers methods to use the new static methods Random::*() instead
  • (??) Deprecate anything
  • Rejoice

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.1

Component
PHPUnit 

Last updated about 5 hours ago

Created by

🇮🇹Italy mondrake 🇮🇹

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

Comments & Activities

Production build 0.71.5 2024