rector: How does one add a failing test case?

Question

I earlier asked another question here, but then that question morphed to something totally different so thought it best to create a new issue which is on topic. I am trying to gain a better understand how to perform https://github.com/rectorphp/rector/blob/main/docs/how_to_add_test_for_rector_rule.md, and have a few questions.

  1. Should Symfony be installed first (i.e. new symfony my_project)
  2. Should phpunit be installed first (i.e. composer require --dev phpunit/phpunit ^9)
  3. Is PhpStorm required? Note that I do not use it.
  4. Is there any other software (other than composer require rector/rector --dev of course) that needs to be installed?
  5. Must content from rector-src be used? Reason I ask is it has rules-tests/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector/Fixture.
  6. When performing Step 3 Find the Rector Test Case, where are these directories and files located, and are they somehow automatically created by Rector (which they are not being done so for me) or do I manually add them? If I must manually add them, how do I know what content to include other than copying what is in rector-src?
  7. If PHPUnit fails and I’ve successfully added a test case, where do I find it so I can include with any bugs I might find?

I ended up copying rules-tests from rector-src to my project and then added add_final.php.inc to match the the script shown in step 4 Add Change or No-Change Test Fixture File. But when executing vendor/bin/phpunit rules-tests/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector/FinalizeClassesWithoutChildrenRectorTest.php, got some errors that /src/constants.php and /preload.php were missing so just copied them from rector-src, and then that Class Symfony\Bridge\PhpUnit\SymfonyTestsListener does not exist and concluded I am obviously doing something wrong 😦

Appreciate any help and apologize if I should already know how to do this.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 38 (21 by maintainers)

Most upvoted comments

I sent you a PR as requested and got a little inspired and actually sent you two more. Please let me know whether I did it correctly or need to do it differently going forward.

Yes, I found https://github.com/rectorphp/rector-doctrine/blob/main/config/sets/doctrine-orm-29.php very helpful! Still a little confused where sets are located but just found some of them at ./vendor/rector/rector/vendor/rector/rector-doctrine/config/sets. Will look more into. Thanks

Thanks Tomas!

Merged the PR. All works as expected meaning I get the same results on Github Actions as I do on my server where neither show a diff where I believe they should. Makes me happy as it is now reproducible!

Also, appreciate the update to the workflow yaml script. Don’t understand it 100% but do get the general flow.

Under the action yaml file, looks like the various uses under steps first prepares the workflow environment:

  1. actions/checkout@v2. Allows workflow to access repository (https://github.com/actions/checkout).
  2. shivammathur/setup-php@v2. Sets up PHP as version 8.0 without coverage support (https://github.com/shivammathur/setup-php).
  3. ramsey/composer-install@v1. Allow composer to setup dependencies. (https://github.com/ramsey/composer-install)

Then, in step 4, vendor/bin/rector process src/rector-testing --dry-run --debug is executed and reproduced the exact same output that on my server (except for the location of the progress bar which doesn’t matter).

Post run steps 5 and 6 appear to just clean up the environment, and step 7 appears to clean up the vm.

Thanks Tomas, The version where rector is installed using composer, right? Like it is now? Thanks

https://github.com/NotionCommotion/rector-symfony