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->prophesize()

Proposed resolution

In the data providers, replace $this->prophesize() with (new Prophet())->prophesize() or similar so to get the mock object directly from Prophecy and not via the trait that is meant to be included in test objects.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3354382

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: mondrake » Unassigned
Issue summary: View changes
Status: Active » Needs review
smustgrave’s picture

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

This looks very interesting, as I've gotten more into Unit testing vs just functional. Don't mind marking this.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

  • catch committed 3c7ffa19 on 10.1.x
    Issue #3354382 by mondrake: [PHPUnit 10] Provide a static viable...

  • catch committed 6ef863a2 on 11.x
    Issue #3354382 by mondrake: [PHPUnit 10] Provide a static viable...
catch’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

This looks good - I wonder if it's something we should try to put into phpstan/rector for 11.x readiness, will ask in slack.

Committed/pushed to 11.x and cherry-picked to 10.1.x, thanks!

mondrake’s picture

I wonder if it's something we should try to put into phpstan/rector for 11.x readiness

phpstan/phpstan-phpunit already checks that... but only if PHPUnit 10 is in use, which does not help much in preparation to adopt PHPUnit 10.

See upstream https://github.com/phpstan/phpstan-phpunit/issues/178

catch’s picture

Status: Fixed » Needs work
Issue tags: +Needs change record

Spoke to @bbrala and @mglaman in slack a bit about how to communicate this (via phpstan/rector and in general).

We came up with something like - adding a new PHPUnit 10 change record, which we can relate to all of the PHPUnit 10 changes, and then that can include the kinds of changes contrib needs to make.

For example for this issue we could talk about static data providers and $prophet = new Prophet(); $prophet->prothesize(); instead of $this->prothesize() - even though it's not Drupal API that we're changing, it'd be a useful cheat sheet for people.

Re-opening and marking needs work for that, leaving the commit in.

mondrake’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
catch’s picture

Status: Needs review » Fixed

That looks like a great start!

quietone’s picture

Status: Fixed » Needs work
Issue tags: +Needs change record updates

I am working through the unpublished change records. The title of the CR here is 'PHPUnit 10' which at first I thought meant that PHPUnit 10 was being used, which I also knew was not true. So, to avoid confusion I think the title needs to be changed.

And I read that the CR is intended to be used for multiple issues, which is fine. However, there are several issues for PHPUnit and they will be committed to different versions and there is only one version field. By that, we actually do need multiple CRs. It could be made simple by having one CR per version. But to have all the data in one place, what do you think of having a wiki page for the PHPUnit changes that the individual CRs can point to. The CR's would then be very short. The wiki page could be in PHPUnit in Drupal.

catch’s picture

Status: Needs work » Fixed
Issue tags: -Needs change record updates

I've changed the title to "Changes required for PHPUnit 10 compatibility".

However, there are several issues for PHPUnit and they will be committed to different versions and there is only one version field. By that, we actually do need multiple CRs.

I'm not sure this is necessary. While it's true that there are multiple issues committed to different versions, we're not changing APIs in those issues (or not the vast majority), instead we're just changing individual tests so that they don't use APIs deprecated by PHPUnit. It's useful to document the changes that core had to do to make it easier for contrib when they're doing the same things, but we're not responsible for those API changes ourselves, and we'll only update to PHPUnit 10 in Drupal 11.

Status: Fixed » Closed (fixed)

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