Skip to content

Pest Extension (Is there a way to tell phpactor what "$this" is, in some files?) #2344

Description

@einenlum

Hi Dan,

Hope you're doing well.

I'm using Pest more and more and Pest tests look like this:

<?php
// tests/Feature/BrandsTest.php

test('brands', function () {
    $response = $this->get('/brands');

    $response->assertStatus(200);
});

$this in this context is not known to phpactor (neither to intelephense), which makes sense. But under the hood it's Tests\TestCase, thanks to this line:

// tests/Pest.php
uses(TestCase::class)->in('Feature');

For now I'm stuck with adding this docblock to each test:

<?php

test('brands', function () {
    /** @var Tests\TestCase $this */
    $response = $this->get('/brands');

    $response->assertStatus(200);
});

I imagine it would be out of the scope of phpactor to parse the Pest file, but is there a way to tell phpactor (in a .phpactor.yml file for example) what $this refers to in a specific set of files (like in a whole folder)?

Thanks!

Edit: Found this related issue for Intelephense. I guess using the get function as stated in Pest doc is a good workaround to this problem.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions