Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Stop using deprecated setMethods(). #426

Closed
GaryJones opened this issue Sep 30, 2021 · 1 comment · Fixed by #427
Closed

Tests: Stop using deprecated setMethods(). #426

GaryJones opened this issue Sep 30, 2021 · 1 comment · Fixed by #427
Assignees
Milestone

Comments

@GaryJones
Copy link
Contributor

As per sebastianbergmann/phpunit#3687 setMethods() is deprecated and will be removed in PHPUnit 10.

The option is to use onlyMethods() instead, but this needs checking to see if PHPUnit-Polyfills handles this for PHPUnit 7, which we still need to test PHP 7.1.

We only have a single instance of setMethods(), so we may be able to fashion a workaround if it's not polyfilled.

@GaryJones GaryJones added this to the 3.0.0 milestone Sep 30, 2021
@GaryJones GaryJones self-assigned this Sep 30, 2021
@GaryJones
Copy link
Contributor Author

As shown at https://github.com/Parsely/wp-parsely/runs/3754851373?check_suite_focus=true the onlyMethod() method is not polyfilled.

I've opened Yoast/PHPUnit-Polyfills#58 to see if it can be polyfilled.

Untested, but I think a workaround would be like:

$mock_builder = $this->getMockBuilder( Integration::class );
if ( method_exists( $mock_builder, 'onlyMethods' ) ) {
	$mock_integration = $mock_builder->onlyMethods( array( 'integrate' ) )->getMock();
} else {
	$mock_integration = $mock_builder->setMethods( array( 'integrate' ) )->getMock();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant