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.
- Should Symfony be installed first (i.e.
new symfony my_project) - Should phpunit be installed first (i.e.
composer require --dev phpunit/phpunit ^9) - Is PhpStorm required? Note that I do not use it.
- Is there any other software (other than
composer require rector/rector --devof course) that needs to be installed? - Must content from rector-src be used? Reason I ask is it has
rules-tests/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector/Fixture. - 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?
- 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)
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. ThanksThanks 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
usesunderstepsfirst prepares the workflow environment:Then, in step 4,
vendor/bin/rector process src/rector-testing --dry-run --debugis 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