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\Randomthat copies the methods fromDrupal\Tests\RandomGeneratorTrait, but changes them to static - Make
Drupal\Tests\RandomGeneratorTrait::random*()andDrupal\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 methodsRandom::*()instead - (??) Deprecate anything
- Rejoice
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3353658
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:
- 3353658-phpunit-10-provide
changes, plain diff MR !3820
Comments
Comment #3
mondrakeWorking on this
Comment #4
mondrakeComment #5
smustgrave commentedThere a way to get this to run against phpunit 10?
Comment #6
mondrake#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.Comment #7
smustgrave commentedAh 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.
Comment #8
mondrakeYes... one step after another... :)
Comment #9
mondrakeMissed one.
Comment #10
smustgrave commentedLGTM
Comment #11
catchAgreed this looks like a good step forwards.
Committed 609e744 and pushed to 10.1.x. Thanks!
Comment #13
catchAdded 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.
Comment #15
mondrakeFiled #3358186: [META] Deprecate non-static random generation methods from RandomGeneratorTrait for follow up.