drift icon indicating copy to clipboard operation
drift copied to clipboard

[Rector] Higher Order Tests

Open olivernybroe opened this issue 5 years ago • 1 comments

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

olivernybroe avatar May 28 '20 11:05 olivernybroe

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();

alexmartinfr avatar May 28 '20 22:05 alexmartinfr