rector icon indicating copy to clipboard operation
rector copied to clipboard

When using `custom-rule` command, add rector test suite to PHPUnit config if one does not already exist

Open DaveLiddament opened this issue 2 years ago • 1 comments

Feature Request

Thanks for a great tool. I love the custom-rule command.

It would be even better if this command setup phpunit.xml, in the same way composer.json is updated.

If all the following are true:

  • phpunit.xml file exists.
  • there is NO rector test suite

Then Rector adds the rector testsuite to phpunit.xml. The phpunit.xml diff would look a bit like this:

    <testsuites>
        <testsuite name="default">
	    <directory>tests</directory>
        </testsuite>
+       <testsuite name="rector">
+          <directory>utils/rector/tests</directory>
+       </testsuite>
    <testsuites>

Rector would report is has done this, in a similar way to it reports updating composer.json. E.g.

 [OK] We also update phpunit.xml, to add a rector test suite. You can run the rector tests by running: phpunit --testsuite rector

DaveLiddament avatar Feb 13 '24 18:02 DaveLiddament

Hey Dave! Glad you find it useful :+1: Sounds reasonable... I actually do the same step manually myself.


Care to send PR to add this feature? :pray:

The composer.json update happens here - https://github.com/rectorphp/rector-src/blob/d62be327173447695dea93ff52d67d087d9fb9d4/src/Console/Command/CustomRuleCommand.php#L109-L127

So it would require adding similar condition for phpunit.xml

TomasVotruba avatar Feb 14 '24 11:02 TomasVotruba