pestphp / drift

[WIP] Command-line tool to migrate your PHPUnit tests to Pest
https://pestphp.com/docs/guides/drift
MIT License
28 stars 7 forks source link

[Rector] Ordering #7

Open olivernybroe opened 4 years ago

olivernybroe commented 4 years ago

Let's create a new rector which orders the test alphabetically

The reason for using a new rector is so we can optionally enable/disable it and decouple it from the base rector which is about just refactoring to pest test cases, not making them nicer.

owenvoke commented 4 years ago

I've been looking into this, and I can't work out if this is actually possible. This is what I've started with, however the FuncCall doesn't appear to have access to other functions in the same file. I was looking at this set for ideas, but that's all about re-ordering class nodes, etc. 🤔

olivernybroe commented 4 years ago

Hmm...

@TomasVotruba how do we create a rector for reordering function calls in a file? Normally I would take the parent node, but the parent node is the file itself and I can't find a node type for that. Any help would be highly appreciated :heart:

TomasVotruba commented 4 years ago

Quick answer from phone: use Class_ and stmts.

Best practice: Parents are hard to change, as in real life ;), so better go with the higher node and change its children.

Also check for Order Rector rules in core. There might be some inspiration ☺️

Let me know if you need more.

owenvoke commented 4 years ago

Does Class_ work when there isn't a class in the file? It's just function calls such as:

it('does test1')->skip();
it('does test2')->skip();