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

Cannot mock readonly class #1317

Open
Gyalomalom opened this issue Aug 2, 2023 · 3 comments · May be fixed by #1319
Open

Cannot mock readonly class #1317

Gyalomalom opened this issue Aug 2, 2023 · 3 comments · May be fixed by #1319
Assignees
Labels
Feature Request request a new feature Major Backwards Incompatible changes
Milestone

Comments

@Gyalomalom
Copy link

Mockery Version

1.5.1

PHP Version

PHP 8.2

Issue Description

After upgrading to PHP 8.2 and making a number of classes readonly, our tests began failing. We use a lot of dependency injection so in those cases we need to mock the injected classes. I get the following error:

In EvalLoader.php(34) : eval()'d code line 30:
                                                                                                                                                                               
Non-readonly class Mockery_7_ClassToBeMocked cannot extend readonly class ClassToBeMocked

If I remove readonly from the class and instead make the properties readonly, it works, so currently we are using this approach as a workaround, but I would like to know if Mockery is planning to add support to readonly classes in the future.

Steps to Reproduce

Create a mock of a readonly class using Mockery.

Expected Behavior

The mock is successfully created.

Actual Behavior

An exception is thrown.

Exception or Error

In EvalLoader.php(34) : eval()'d code line 30:
                                                                                                                                                                               
Non-readonly class Mockery_7_ClassToBeMocked cannot extend readonly class ClassToBeMocked

Additional Information

No response

@Gyalomalom Gyalomalom added the triage needs to be triaged label Aug 2, 2023
@ghostwriter ghostwriter self-assigned this Aug 2, 2023
@ghostwriter ghostwriter linked a pull request Aug 3, 2023 that will close this issue
10 tasks
@ghostwriter ghostwriter linked a pull request Aug 3, 2023 that will close this issue
10 tasks
@ghostwriter
Copy link
Member

Hey @Gyalomalom,

Thanks for reporting this issue.

I wanted to give some updates, but I don't have the full resolution yet.

Working on a fix for this in #1319 but it is not that simple (and may not be possible because of readonly class restrictions) so I need a little more time to address this issue.

I really appreciate your patience as we work through this issue together, thank you.

@ghostwriter ghostwriter added Bug An error or unexpected behavior. and removed triage needs to be triaged labels Aug 7, 2023
@Gyalomalom
Copy link
Author

Gyalomalom commented Aug 7, 2023

Hello @ghostwriter . Thank you for the update, I will keep an eye on this issue.

@neoighodaro
Copy link

Hey... any update here?

@ghostwriter ghostwriter added Feature Request request a new feature Major Backwards Incompatible changes and removed Bug An error or unexpected behavior. labels Mar 16, 2024
@ghostwriter ghostwriter added this to the 2.0.0 milestone Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request request a new feature Major Backwards Incompatible changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants