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

Backward Compatibility break in PHPUnit\Framework\Constraint\Constraint #5690

Closed
stof opened this issue Feb 2, 2024 · 9 comments
Closed
Assignees
Labels
type/bug Something is broken version/11 Something affects PHPUnit 11

Comments

@stof
Copy link
Contributor

stof commented Feb 2, 2024

Q A
PHPUnit version 11.0
PHP version 8.2.15
Installation Method Composer / PHAR

Summary

PHPUnit 11.0 has changed the Constraint class to mark it readonly. This is a BC break for all child class (i.e. all custom constraints) because PHP requires that child classes have the same readonly flag than their parent (so either both readonly or none).
This BC break is not mentioned anywhere in the changelog. And it will make it very hard to define custom constraints compatible with multiple PHPUnit versions as it will require using conditional class definitions.

Current behavior

How to reproduce

Install PHPUnit 11 and use custom constraints that were written against previous versions. See symfony/symfony#53731

Expected behavior

@stof stof added the type/bug Something is broken label Feb 2, 2024
@stof stof changed the title Undocument BC break in PHPUnit 11.0 Undocumented BC break in PHPUnit 11.0 Feb 2, 2024
@stof
Copy link
Contributor Author

stof commented Feb 2, 2024

As the change has been rejected in https://wiki.php.net/rfc/readonly_amendments, this readonly flag at the class level effectively splits the classes into 2 incompatible sets as far as inheritance is concerned.
Adding it or removing it on non-final classes is a BC break.

@derrabus
Copy link
Contributor

derrabus commented Feb 2, 2024

FTR, the corresponding commit was d82f5ad. I didn't find any discussion around this change though.

As @stof said, this change is a huge pain for 3rd party PHPUnit extensions that maintain compatibility for multiple PHPUnit versions. It would be really helpful if we could remove the readonly flag from classes that are meant to be extended downstream and have existed in PHPUnit 10 already.

Then again, removing the readonly flag from abstract classes like Constraint is a BC break as well. Not sure, how many projects have migrated their constraints to the new readonlyclasses already. Maybe taking back that change is acceptable if we are quick. 😕

@sebastianbergmann sebastianbergmann self-assigned this Feb 2, 2024
@sebastianbergmann sebastianbergmann added type/bug Something is broken and removed type/bug Something is broken labels Feb 2, 2024
@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Feb 2, 2024

This is a BC break for all child class (i.e. all custom constraints) because PHP requires that child classes have the same readonly flag than their parent (so either both readonly or none).

This is a BC break, but it was done in a major version, so I expected this to be fine.

Do you really expect me to revert this change or is amending the ChangeLog to cover this change enough?

Nevermind, I'll revert this change and release PHPUnit 11.0.1 in a bit.

@sebastianbergmann sebastianbergmann changed the title Undocumented BC break in PHPUnit 11.0 Undocumented BC break in PHPUnit\Framework\Constraint\Constraint Feb 2, 2024
@sebastianbergmann sebastianbergmann changed the title Undocumented BC break in PHPUnit\Framework\Constraint\Constraint Backward Compatibility break in PHPUnit\Framework\Constraint\Constraint Feb 2, 2024
@sebastianbergmann sebastianbergmann added the version/11 Something affects PHPUnit 11 label Feb 2, 2024
@stof
Copy link
Contributor Author

stof commented Feb 2, 2024

Well, this makes it a huge pain for projects providing custom constraints. It would be great to be able to support the 2 major versions of PHPUnit at the same time (for a package that is dedicated to PHPUnit constraint, making a new major version

so I expected this to be fine

doing BC breaks in major version is indeed OK regarding semver. But to me, the fact that it was not announced (while being the most painful BC break of the release) is not. If this was known to be a BC break when doing it, it should have been announced..

Note that the commit included similar changes for some other non-final classes (TestData, TestSuite, etc...). As those are less common in third party code, it might be OK to keep them readonly in 11.x but I would still expect the changelog to be amended for them.

@stof
Copy link
Contributor Author

stof commented Feb 2, 2024

Thanks for the decision to revert it. It will make things a lot easier.

sebastianbergmann added a commit that referenced this issue Feb 2, 2024
@sebastianbergmann
Copy link
Owner

PHPUnit 11.0.1 has been released with this fix.

@stof
Copy link
Contributor Author

stof commented Feb 2, 2024

@sebastianbergmann what about the changelog amending for other non-internal non-final classes that were turned readonly ?

@sebastianbergmann
Copy link
Owner

@sebastianbergmann what about the changelog amending for other non-internal non-final classes that were turned readonly ?

As far as I can see, this only affects value objects that are passed from PHPUnit's event system to subscribers. Please see the section titled "Event System: Value Objects" that I just added to https://phpunit.de/backward-compatibility.html.

@derrabus
Copy link
Contributor

derrabus commented Feb 3, 2024

Thank you very much, @sebastianbergmann!

szepeviktor added a commit to conedevelopment/root that referenced this issue Apr 3, 2024
szepeviktor added a commit to szepeviktor/laravel_skeleton-application that referenced this issue Apr 3, 2024
driesvints pushed a commit to laravel/laravel that referenced this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken version/11 Something affects PHPUnit 11
Projects
None yet
Development

No branches or pull requests

3 participants