rectorphp / rector-phpunit

Rector upgrade rules for PHPUnit
http://getrector.com
MIT License
61 stars 46 forks source link

PHPUnit rules work only with withRules option #342

Closed chithract closed 1 week ago

chithract commented 1 week ago

I use rector 1.1.1 and PHPUnit 10.5.24.

My configuration is:

return RectorConfig::configure()
  ->withPaths([
     __DIR__ . '/src',
      __DIR__ . '/tests',
  ])
  ->withPhpSets(php82: true)
  ->withPreparedSets(deadCode: true, codeQuality: true)
  ->withSets([PHPUnitSetList::PHPUNIT_100])
  ->withSkip([
      SimplifyIfElseToTernaryRector::class,
  ]);

I created dummy test files to check whether the rules apply correctly. The test file contains the below contents:

use PHPUnit\Framework\TestCase;

final class SomeTest extends TestCase
{
    public function test()
    {
        $someMockObject = $this->createMock(SomeClass::class);

        $someMockObject->method('someMethod')
            ->willReturn(100);

    }
}

When I run vendor/bin/rector process tests/SomeTest.php --dry-run it gives [OK] Rector is done!.

No rules are applied. When I add the below line to config:

>withRules([CreateMockToAnonymousClassRector::class]);

It applies the rector changes correctly. Why doesn't it work with withSets([PHPUnitSetList::PHPUNIT_100])?

Please help.

samsonasik commented 1 week ago

CreateMockToAnonymousClassRector is not part of any set, so you need to define yourself with withRules()