| Q | A
| --------------------| ---------------
| PHPUnit version | 8.3.1
| PHP version | N/A
| Installation Method | Composer / PHAR
Default value of $methods argument is null hence calling MockBuilder::setMethods() without argument sets MockBuilder::$methods property to null.
With setMethods() deprecated and default value of MockBuilder::$methods being [] it's no longer possible to set it to null with the new methods onlyMethods() or addMethods().
The behaviour of setMethods() has not been changed and tests that use it should continue to work as-is.
CC @DFoxinator
True but we want to be future proof and avoid seeing messages related to deprecated methods usage when running tests :slightly_smiling_face:.
So only option is to change our usage?
We actually had a discussion around this here: https://github.com/sebastianbergmann/phpunit/pull/3687#discussion_r283092106
I was on the fence, but I though it was a good argument that the behavior of passing null didn't really seem valuable/to make sense so going forward it seemed better to simplify it I think and clean it up in the new onlyMethods and addMethods.
@DFoxinator In that case MockObject\Generator::getMock() should also not accept null for it's $methods argument?
@ADmad You should not care about getMock() as it is internal.
Okay, just wanted to be sure since earlier today removal of supposedly internal classes blew up things :)
@ADmad because of a small oversight on my part (sorry!), there was a bug with onlyMethods/addMethods in 8.3.(0-2) that made them not behave correctly when you pass a blank array. Now (in 8.3.3), passing a blank array to onlyMethods([]) the same behavior as passing null to setMethods (you're saying to not mock any methods), so it's really an easy drop-in replacement where if you need to you can just pass [] instead of null if you're moving over a large test suite.
Just to add, I still recommend looking on a case-by-case basis though. This onlyMethods/addMethods change is revealing so many code/test smells in the tests I work on (some legacy stuff going back many years) it's crazy haha. So many methods removed from the code years ago still mocked, mocks where you don't need a mock at all, etc.
@DFoxinator Thanks for the update.
Most helpful comment
The behaviour of
setMethods()has not been changed and tests that use it should continue to work as-is.