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

[Bug]: mixed-in expectation object causes IDE type errors #1166

Open
wand2016 opened this issue Jun 7, 2024 · 1 comment
Open

[Bug]: mixed-in expectation object causes IDE type errors #1166

wand2016 opened this issue Jun 7, 2024 · 1 comment
Labels

Comments

@wand2016
Copy link

wand2016 commented Jun 7, 2024

What Happened

With using a mixed-in expectation object, method chaining results in IDE type errors:

        expect($response->content())
            ->toBeJson()
            ->json()
            ->not()->toHaveKey('errors')
            ->toHaveKey('data')
            ->data->toEqual(...);
             // ^ IDE type error occurs

* @return self<TValue>

Suggested fix:

-    * @return self<TValue>
+    * @return $this

Changing the PHPDoc return type to $this seems to be a better solution to avoid these IDE type errors.

How to Reproduce

        expect($response->content())
            ->toBeJson()
            ->json()
            ->not()->toHaveKey('errors')
            ->toHaveKey('data')
            ->data->toEqual([]);

image

The suggested fix above solves the problem:

image

Sample Repository

No response

Pest Version

2.x-dev

PHP Version

8.2.15

Operation System

Linux

Notes

pestphp/pest-plugin version is v2.1.1

@michaeldyrynda
Copy link
Collaborator

michaeldyrynda commented Sep 11, 2024

Flagging this one @nunomaduro based on our chat.

I'm less concerned with the type errors, and more about the lack of completion of the proxied object.

expect($user)-> will provide completion for methods on the Pest\Expectation object, but nothing from the $user, which makes it possible to introduce failing tests because typos, for example, will lead to an assertion on null.

CleanShot 2024-09-11 at 10 17 31

We certainly get the @template annotations for the generics, etc., but to no avail.

CleanShot 2024-09-11 at 10 18 30

I've tried making the change as in the linked PR (#1168), but that doesn't seem to yield the expected outcome.

I'm not sure how exactly to remedy this situation, or if it's possible. Or if this is just something in my setup, though one of my colleagues has suggested he also has no completion in PhpStorm (and seems to make it chug, at that).

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

Successfully merging a pull request may close this issue.

2 participants