-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] fix BC-breaking property in WebTestAssertionsTrait #31880
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
Conversation
Why is this a trait BTW, and not plain methods on WebTestCase? |
4860faf
to
835280b
Compare
I can’t remember why, maybe @Pierstoval can help us |
The trait was not discussed, I thought it was convenient to have all assertions in one place, especially when needing them statically. A fix to make the client static in the trait is welcomed, indeed. |
835280b
to
3b50107
Compare
3b50107
to
6253926
Compare
@@ -30,12 +30,12 @@ trait WebTestAssertionsTrait | |||
{ | |||
public static function assertResponseIsSuccessful(string $message = ''): void | |||
{ | |||
self::assertThat(static::getResponse(), new ResponseConstraint\ResponseIsSuccessful(), $message); | |||
self::assertThat(self::getResponse(), new ResponseConstraint\ResponseIsSuccessful(), $message); |
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.
Traits should be self contained, we shouldn't provide these as extensibility points.
} | ||
|
||
private static function getClient(): KernelBrowser | ||
private static function getClient(KernelBrowser $newClient = null): ?KernelBrowser |
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.
Why would it return null
? If the client is null, it should alway throw an exception, shouldn't it? If it's null, all the rest of the trait's codebase would be forced to check for null pointer 😕
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.
related to my answer to your other comment: getClient(null)
returns null
static::fail(\sprintf('A client must be set to make assertions on it. Did you forget to call "%s::createClient"?', __CLASS__)); | ||
static $client; | ||
|
||
if (0 < \func_num_args()) { |
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.
What is the reason to not use if ($newClient) {
?
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.
Because we want to be able to reset the state using getClient(null)
, while getClient()
shouldn't reset anything
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.
Seems fair
Thank you @nicolas-grekas. |
…tionsTrait (nicolas-grekas) This PR was merged into the 4.3 branch. Discussion ---------- [FrameworkBundle] fix BC-breaking property in WebTestAssertionsTrait | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31653 | License | MIT | Doc PR | - No properties should be exposed. Commits ------- 6253926 [FrameworkBundle] fix BC-breaking property in WebTestAssertionsTrait
No properties should be exposed.