Problem/Motivation

#3130606: MockBuilder::setMethods is deprecated in PHPUnit8 and removed from PHPUnit10 properly removes all MockBuilder::setMethods calls but the issue #3194768: The plugin system should only consider NULL context values to be empty to facilitate the use of otherwise FALSE values introduced one call to that method again in the Drupal\Tests\Component\Plugin\Context\ContextTest file.

Steps to reproduce

See:

    $mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
      ->setMethods(['getDefaultValue'])
      ->getMockForAbstractClass();

Proposed resolution

Replace the setMethods() method by the onlyMethods() method.

Issue fork drupal-3250629

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

paulocs created an issue. See original summary.

paulocs’s picture

Assigned: paulocs » Unassigned
Status: Active » Needs review
Related issues: +#3130606: MockBuilder::setMethods is deprecated in PHPUnit8 and removed from PHPUnit10
paulocs’s picture

longwave’s picture

As https://github.com/sebastianbergmann/phpunit/issues/4775 is still open maybe we should temporarily add our own deprecation to avoid this happening again?

paulocs’s picture

How is it possible to trigger a deprecation from a third party method call? Do you have any example so i can see how its done?

longwave’s picture

We could add a method override to one of our traits (maybe PhpUnitCompatibilityTrait) that triggers the deprecation and then just calls the parent method?

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Ignore #5/#7, I don't think this is feasible as MockBuilder is declared final so even if we jump through hoops to replace it we can't then extend it as we would need to.

Therefore we can't fix that here and will have to wait for upstream, in the meantime this patch is RTBC.

mondrake’s picture

Yep that's in the milestones for PHPUnit 9.6, but ATM the situation of PHPUnit releases' timing is rather unclear.

  • catch committed 588951b on 9.4.x
    Issue #3250629 by paulocs, longwave: MockBuilder::setMethods is...

  • catch committed f6ffe6a on 9.3.x
    Issue #3250629 by paulocs, longwave: MockBuilder::setMethods is...
catch’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.4.x and cherry-picked to 9.3.x, thanks!

Thanks for investigating whether we could add our own deprecation notice, but agreed that looks like a pain.

Status: Fixed » Closed (fixed)

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