Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating helpers — previous private methods in PHPUnit #6

Closed
nunomaduro opened this issue May 13, 2020 · 2 comments · Fixed by #7
Closed

Creating helpers — previous private methods in PHPUnit #6

nunomaduro opened this issue May 13, 2020 · 2 comments · Fixed by #7

Comments

@nunomaduro
Copy link
Member

nunomaduro commented May 13, 2020

Just committed something kind of experimental to the dev-master.

Feature added: The test helper called without any arguments resolves the current test instance.

Use Case 1: Creation of helpers that depend of the current test instance. I think this is dope.

<?php

function actingAs($user)
{
    return test()->actingAs($user);
}

it('has home', function () {
    $user = factory(User::class)->create();

    actingAs($user)->get('/')->assertStatus(200);
});

Use Case 2: Solves some IDE issues ( see #5):

<?php

it('does something', function () {
    test()->assertAuthenticat.. // <- IDE support here.
});

Any thoughts on this? You can try it out doing:

composer require pestphp/pest:dev-master
@nunomaduro nunomaduro changed the title Creating helpers ( previous private methods in PHPUnit ) Creating helpers — previous private methods in PHPUnit May 13, 2020
@fetzi
Copy link
Contributor

fetzi commented May 14, 2020

I find it's an elegant solution to get the current test case instance 👏

@jkniest
Copy link

jkniest commented May 14, 2020

I personally like this approach a lot. Especially for use case 2. This could also solve some of the issues until a phpstorm plugin is released with autocompletion and static code analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants