-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[BrowserKit] Avoid nullable values in some Client's methods #26509
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
068f87f
to
1f1a571
Compare
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.
tend to agree 👍 at least for getCrawler()
as you should get it from request()
.
@@ -183,20 +183,28 @@ public function getCookieJar() | |||
/** | |||
* Returns the current Crawler instance. | |||
* | |||
* @return Crawler|null A Crawler instance |
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.
should be reverted as it's still valid
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.
null
is returned only for BC. There are no cases when null
might be returned.
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.
fact is it's Crawler|null
until 5.0
to me this is different then switching to new API for parameters (@param
), we where want users to provide correct input beforehand.
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.
fact is it's Crawler|null until 5.0
we don't document deprecated APIs
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.
👍 sounds fair while thinking about it. Deprecation message should tell either way.
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.
looks legit to me, good if it can help DX
the deprecation messages need some tweaks
*/ | ||
public function getCrawler() | ||
{ | ||
if (null === $this->crawler) { | ||
@trigger_error(sprintf('The %s() method calling before request() method is deprecated since 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED); |
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.
Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.
(same below)
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.
Thanks for your help, fixed
Thanks for contributing to Symfony ! This looks legit to me too. |
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.
(failures unrelated)
*/ | ||
public function getCrawler() | ||
{ | ||
if (null === $this->crawler) { | ||
@trigger_error(sprintf('Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED); |
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.
Can you add the exception that would be thrown in 5.0 and comment it? That will help when we remove the deprecation notices. Thanks.
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.
@fabpot Please review
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.
Sorry, I was not clear enough. We cannot add the @throws
annotation yet as that would be wrong, but to ease remving the deprecation notices, you can add a line like this bellow the trigger call:
// throw new BadMethodCallException('...');
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.
Fixed
Thank you @ossinkine. |
…thods (ossinkine) This PR was merged into the 4.1-dev branch. Discussion ---------- [BrowserKit] Avoid nullable values in some Client's methods | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes/no | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | License | MIT <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> I suggest the some methods in `Client` should not return `null` for simplify usage. If you are trying to get response from client when `request` method was not called, it seems an exception should be throwed. Commits ------- c2c2853 Avoid nullable values in some Client's methods
I suggest the some methods in
Client
should not returnnull
for simplify usage.If you are trying to get response from client when
request
method was not called, it seems an exception should be throwed.