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

Issue fork drupal-3353658

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

mondrake created an issue. See original summary.

mondrake’s picture

Assigned: Unassigned » mondrake

Working on this

mondrake’s picture

Assigned: mondrake » Unassigned
Issue summary: View changes
Status: Active » Needs review
smustgrave’s picture

There a way to get this to run against phpunit 10?

mondrake’s picture

#5 does not make sense… we are doing this to be able to support PHPUnit 10, like other patches. Individual patches will not pass against it.

EDIT - meaning, we will not have a green test pass with individual patches, we will need to commit them all to qualify the code for PHPUnit 10. The test runs in #3217904: [meta] Support PHPUnit 10 in Drupal 11 currently present the results of running Drupal tests (with heavy limitations to the framework to at least being able to run) with PHPUnit 10. The results of running those, for example https://www.drupal.org/pift-ci-job/2639327, give us input as what are the changes needed, and this is one of them.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Ah good point. Guess we will fix what we can can and see what was missed when updated.

Tried do a spot check through the tests searching for "function provider" (to start) and find any that aren't using random but didn't see any. So can go ahead and mark this as trust what you are doing here.

mondrake’s picture

Guess we will fix what we can can and see what was missed when updated.

Yes... one step after another... :)

mondrake’s picture

Status: Reviewed & tested by the community » Needs review

Missed one.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

LGTM

catch’s picture

Status: Reviewed & tested by the community » Fixed

Agreed this looks like a good step forwards.

Committed 609e744 and pushed to 10.1.x. Thanks!

  • catch committed 609e7442 on 10.1.x
    Issue #3353658 by mondrake, smustgrave: [PHPUnit 10] Provide a static...
catch’s picture

Issue tags: +Needs followup

Added a belated change record here: https://www.drupal.org/node/3358180

I think we need a follow-up to discuss what if anything we want to deprecate, so tagging for that.

mondrake’s picture

Status: Fixed » Closed (fixed)

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