Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method 'setMethods' is deprecated when try to write a PHP Unit Test

I want to create a mock to replace a resource:

$gateway = $this->getMockBuilder('PaymentGateway')
            ->setMethods(['transfer'])
            ->getMock();

I got this warning:

Method 'setMethods' is deprecated

How can I resolve this deprecation?

like image 377
Khaled Boussoffara Avatar asked Mar 06 '26 20:03

Khaled Boussoffara


1 Answers

From now on we are supposed to use either onlyMethods() (which would be the closest equivalent to setMethods() and addMethods():

$gateway = $this->getMockBuilder('PaymentGateway')
            ->onlyMethods(['transfer'])
            ->getMock();

This is explained in the PR (linked from the method PHP doc directly, as seen here).

like image 85
yivi Avatar answered Mar 09 '26 10:03

yivi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!