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] Higher Order Tests #5

Open olivernybroe opened 4 years ago

olivernybroe commented 4 years ago

Let's create a new rector which can migrate a pest test into a higher order test.

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.

Pest Docs

alexmartinfr commented 4 years ago

This will be a problem to tackle:

Warning: You can't access runtime helpers in Laravel, like route, with higher-order tests.

Let's say you want to refactor this test to use Higher Order Functions:

test('has home page', function () {
    $this->get(route('home'))
        ->assertSuccessful();
});

It is using a named route, home, which you can't access with the arrow function syntax. So you'd need to replace that call to route() with the actual route segment, like so:

test('has home page')->get('/')->assertSuccessful();