rectorphp / rector-phpunit

Rector upgrade rules for PHPUnit
https://getrector.com/find-rule?activeRectorSetGroup=phpunit
MIT License
64 stars 47 forks source link

[PHPUnit 10] Change setMethods() to onlyMethods() #267

Closed TomasVotruba closed 11 months ago

TomasVotruba commented 12 months ago

See https://stackoverflow.com/questions/65075204/method-setmethods-is-deprecated-when-try-to-write-a-php-unit-test

eerison commented 12 months ago

yep it was deprecated in 9.x and already dropped in 10.x

https://statics.teams.cdn.office.net/evergreen-assets/safelinks/1/atp-safelinks.html

eerison commented 11 months ago

I'm on this issue ;)

eerison commented 11 months ago

Hey @TomasVotruba

don't you think we could add this into PhpUnit90 rules insteadof PhpUnit10?

TomasVotruba commented 11 months ago

Hey, we usually add the rule when the change will affect users. When people upgrade to PHPUnit 9.0 and this change is not there yet, it would break.

So PHPUnit 10.0 is safer

eerison commented 11 months ago

It does not work for setMethods :'(

https://github.com/rectorphp/rector-phpunit/commit/6d9316d7c1c4ba206fe7904adfeb03521f26cc2b

I guess We need a rule for this :/

eerison commented 11 months ago

it works just in the first case

        //first
        $this->setMethods();

        //second
        $contractMock = $this->getMockBuilder(Contract::class)
            ->disableOriginalConstructor()
            ->setMethods(['getCancelledAt', 'terminate'])
            ->getMock();
samsonasik commented 11 months ago

I am on mobile, disableOriginalConstructor() seems return different instance?

eerison commented 11 months ago

I am on mobile, disableOriginalConstructor() seems return different instance?

I see the issue, I will provide a PR for this

samsonasik commented 11 months ago

Resolved at https://github.com/rectorphp/rector-phpunit/pull/280

eerison commented 11 months ago

I was wondering why this issue wasn't close in the first PR, maybe you have the feling that it wasn't fixed 😄

Just to confirm that it worked <3