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

PHP error instead of PHPUnit error when trying to create test double for read-only class #5113

Closed
wants to merge 1 commit into from
Closed

PHP error instead of PHPUnit error when trying to create test double for read-only class #5113

wants to merge 1 commit into from

Conversation

michaljusiega
Copy link
Contributor

@michaljusiega michaljusiega commented Dec 8, 2022

Hi!

According to new changes delivered in PHP 8.2, we cannot mock readonly classes like final or enum by extending them.

See reference: https://github.com/php/php-src/blob/7850c103894c50c4af4c2632c5ab60480a0fbdd3/Zend/tests/readonly_classes/readonly_class_inheritance_error1.phpt

Or shall we to add readonly keyword into generated mocked class to skip Runtime exception from PHP like: https://github.com/php/php-src/blob/7850c103894c50c4af4c2632c5ab60480a0fbdd3/Zend/tests/readonly_classes/readonly_class_inheritance_success.phpt

@sebastianbergmann sebastianbergmann changed the title Readonly classes cannot be doubled - added new exception. PHP error instead of PHPUnit error when trying to create test double for readonly class Dec 9, 2022
@sebastianbergmann sebastianbergmann changed the title PHP error instead of PHPUnit error when trying to create test double for readonly class PHP error instead of PHPUnit error when trying to create test double for read-only class Dec 9, 2022
@sebastianbergmann
Copy link
Owner

Cherry-picked into 9.5 and merged to main from there. Thank you!

@michaljusiega michaljusiega deleted the feature/readonly-cannot-be-doubled branch December 9, 2022 07:32
@zoltanka
Copy link

zoltanka commented Mar 31, 2023

Is there any reason behind this? Or any way to bypass this? Because this seems to me sofar very self-judgemental, leading to have a lot of boilerplate code just to have something tested.

Also should I mention, that this was pretty much breaking change?

@Aliance
Copy link

Aliance commented Apr 4, 2024

@sebastianbergmann hello, Sebastian. Can you share your thoughts about this?

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

Successfully merging this pull request may close these issues.

None yet

4 participants