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?
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).
thank you for your answer : I replaced setMethods with onlyMethods and i got warning about Class PaymentGateway does not exist !
That’s a different issue. Unrelated with the original question. You should probably pass the fully qualified class name. Or
PaymentGateway::class
when i use addMethods my test is OK and i don't get warnings, i understand that i sould modify my code to work with onlyMethods. Thanks