Yoast / Yoast/PHPUnit-Polyfills

PHPUnit\Framework\MockObject\MockBuilder::onlyMethods is not polyfilled

Open
#58 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: enhancement
Dominant language
PHP
Stars
187
Forks
13
PR merge metrics
No merged PRs in 30d

Description

As per https://github.com/sebastianbergmann/phpunit/pull/3687, the PHPUnit\Framework\MockObject\MockBuilder::setMethods() method was deprecated (soft in PHPUnit 8, hard in PHPUnit 9) and scheduled for removal in PHPUnit 10. It was being replaced by onlyMethods() and addMethods().

In my WordPress plugin codebase, I'm using PHPUnit from 7-9, but whereas various assertions from PHPUnit 9 are polyfilled, the onlyMethods method is not (I'm not using addMethods()).

See https://github.com/Parsely/wp-parsely/runs/3754851373?check_suite_focus=true for a CI run that failed on PHP 7.1 when the test code used onlyMethods(). PHP 7.2 (PHPUnit 8) and above passed fine.

Can these new methods please be polyfilled for earlier versions of PHPUnit?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at PHPUnit\Framework\MockObject\MockBuilder::onlyMethods() and review the existing PHPUnit compatibility behavior around setMethods(). Reproduce the PHP 7.1 failure described in the linked CI run, then verify that onlyMethods() works across the supported PHPUnit versions without requiring addMethods().

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.