Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

[Rector] Higher Order Tests #5

Open
olivernybroe opened this issue May 28, 2020 · 1 comment
Open

[Rector] Higher Order Tests #5

olivernybroe opened this issue May 28, 2020 · 1 comment
Labels
enhancement New feature or request polish If related to polishing pest test

Comments

@olivernybroe
Copy link
Member

olivernybroe commented May 28, 2020

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 olivernybroe added the enhancement New feature or request label May 28, 2020
@alexmartinfr
Copy link
Contributor

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

@olivernybroe olivernybroe added the polish If related to polishing pest test label Jul 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request polish If related to polishing pest test
Projects
None yet
Development

No branches or pull requests

2 participants