rectorphp / rector-pest

MIT License
10 stars 2 forks source link

Multiple expect calls to chainable expect #6

Open olivernybroe opened 1 year ago

olivernybroe commented 1 year ago

When having multiple expect calls right after each other, this can be changed to one expect call using and statements instead

- expect($user)->name->toEqual('Oliver');
- expect($otherUser)->name->toEqual('Tomas');
+ expect($user)->name->toEqual('Oliver')
+     ->and($otherUser)->name->toEqual('Tomas')

Other chainables that can be done is when it is on the same object

- expect($user)->firstName->toEqual('oliver');
- expect($user)->lastName->toEqual('Nybroe');
+ expect($user)
+     ->firstName->toEqual('oliver')
+     ->lastName->toEqual('Nybroe');
TomasVotruba commented 1 year ago

Personally, I find the fluent super hard to read, as it seems the calls are connected - the 1st example. The 2nd example looks fine :+1:

olivernybroe commented 1 year ago

Makes sense.

I agree that the second example is a much nicer place. Then let's go with that being the first thing a rector for chainable should handle.