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

Mocking final classes reports unresolvable type by PHPStan #1411

Open
Ilyes512 opened this issue Apr 15, 2024 · 1 comment · May be fixed by #1410
Open

Mocking final classes reports unresolvable type by PHPStan #1411

Ilyes512 opened this issue Apr 15, 2024 · 1 comment · May be fixed by #1410
Assignees
Labels
Bug An error or unexpected behavior.
Milestone

Comments

@Ilyes512
Copy link

Mockery Version

1.6.11

PHP Version

PHP 8.2

Issue Description

PHPStan returns Return type of call to static method Mockery::mock() contains unresolvable type. when I try to mock a class that is final (in this case it's also readonly, but the issue is caused by the final statement).

$dto = \Mockery::mock(MyFinalClass::class);

In my PHPUnit bootstrap I setup dg\bypass-finals so it "technically" possible to create the mock. This has always worked up to and including version 1.6.9. It's only the last 2 releases of Mockery that PHPStan started reporting the above errors.

Steps to Reproduce

  1. Create a final class.
  2. Try and mock the final class in a PHPUnit test with dg/bypass-finals configured in PHPUnit's bootstrap file.
  3. Run PHPStan.

Expected Behavior

No errors PHPStan errors

Actual Behavior

PHPStan reports on the line with Mockery::mock():

 Return type of call to static method Mockery::mock() contains unresolvable type.

Exception or Error

No response

Additional Information

No response

@Ilyes512 Ilyes512 added the triage needs to be triaged label Apr 15, 2024
@Ilyes512 Ilyes512 changed the title Mocking final classes is broken with latest 2 releases Mocking final classes reports unresolvable type by PHPStan Apr 15, 2024
@ghostwriter
Copy link
Member

Hey @Ilyes512,

You are absolutely right, that was my mistake, the doc comments were incomplete.

I believe we are working on this in #1410, can you please test that branch "mockery/mockery": "1.6.x-dev#1c67601", and report any other issues found by each tool you’re using for static analysis.

Thank you for reporting this issue.

@ghostwriter ghostwriter added Bug An error or unexpected behavior. and removed triage needs to be triaged labels Apr 15, 2024
@ghostwriter ghostwriter self-assigned this Apr 15, 2024
@ghostwriter ghostwriter added this to the 1.6.12 milestone Apr 15, 2024
@ghostwriter ghostwriter linked a pull request Apr 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An error or unexpected behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants