-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PhpUnitBridge] Add ExpectUserDeprecationMessageTrait
#54593
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
[PhpUnitBridge] Add ExpectUserDeprecationMessageTrait
#54593
Conversation
5c769cc
to
24ff1b6
Compare
src/Symfony/Component/Cache/Tests/Adapter/CouchbaseCollectionAdapterTest.php
Outdated
Show resolved
Hide resolved
24ff1b6
to
66430f3
Compare
c5093c3
to
4fd7256
Compare
4fd7256
to
2485e15
Compare
ExpectUserDeprecationMessageTrait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is surprisingly simple. Well done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! Thanks Alexander.
Thank you @derrabus. |
|
||
final protected function expectUserDeprecationMessage(string $expectedUserDeprecationMessage): void | ||
{ | ||
$this->expectDeprecation($expectedUserDeprecationMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful. The PHPUnit 11 API performs an exact match of the deprecation message. expectDeprecation
uses assertStringMatchesFormat
. So this is not a good polyfill (tests that rely on format placeholders would break when using PHPUnit 11 which performs exact match)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to escape those placeholders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can escape by doubling %
(like in sprintf
patterns)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I replace all %
with %%
and I should be good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should, yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR was merged into the 4.x branch. Discussion ---------- Switch to expectUserDeprecationMessage() This PR leverages symfony/symfony#54593. This will make it easier to switch to a vanilla PHPUnit 11 in the future. Commits ------- 0ab26b0 Switch to expectUserDeprecationMessage()
This PR was merged into the 7.2 branch. Discussion ---------- Switch to ExpectUserDeprecationMessageTrait | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT This PR switches some tests added after #54593 to our new trait, allowing us to run those under PHPUnit 11 as well. Commits ------- d923c28 Switch to ExpectUserDeprecationMessageTrait
PHPUnit 11 introduces a method
expectUserDeprecationMessage()
which lets us define which deprecation messages we expect the tested code to raise. This new method can replace our ownexpectDeprecation()
method once we upgrade to PHPUnit 11.This PR introduces a
ExpectUserDeprecationMessageTrait
that polyfills this method for older PHPUnit versions. This allowed me to run all tests that I've migrated toexpectUserDeprecationMessage()
with PHPUnit 11.