-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Adds magic status methods and assertions #45734
Conversation
@timacdonald great catch 👏 👏 |
That's amazing @timacdonald! 💪🏼 |
I think I'd prefer |
What about code completion? |
Reading, understanding and debugging that magic is a lot harder than a few dozen of one-liner methods that are statically analysable without, err, more magic |
It is, Only description that is technically wrong is |
Since this doesn't seem that popular of a PR 😅 maybe it is best we table this for now, or isolate all of this methods explicitly in a trait so they are self-contained and don't bloat up the main class. |
I think the reason why there is a flood of these status code PRs is because the one for 404 got merged (link below) and people thought that would be an easy way to score a merged PR 😂. by doing it for many other status codes Not really because there is a "thirst" from the community. I think. that said I do think 45681 should be merged as not found is such a common use case. Same thing happen with the inspiring quotes last time. |
Possible, but I do see why that PR (45681) was made, and I can also see why it didn't get pushback from the community. Having helper functions for things that developers do often is great. Currently there are 4 helper functions for specific status codes, and those four make sense. When calling an API you're very likely to check if the status is This PR makes more sense from a DX point of view, it's easier to reason about a piece of code that reads I think the reason why this got backlash is because for better or worse a large part of the community doesn't like "magic" methods. 🤷♂️ |
Imho that PR #45681 should be reverted. There was not even 3 hours between the PR and the merge which probably explains why not a single comment was made. I think every single one of those The only ones that might have some merrit that currently exist are (then again the whole Laravel wrapper around Guzzle is meh and just renames/adds some functions for slightly less code; I've been using the actual Guzzle package for ages and it works completely fine as is) |
As seen with may recent PRs, there is a thirst from the community to be able to have named status code methods.
This PR aims to bring named methods to all possible places without the need for a gazillion individual methods.
Test response
Http client response
Recent attempts to add a variety of named methods:
conflict
method to http client response #45718paymentRequired
helper to Http Client response #45698notFound
helper to Http Client response #45681assertBadRequest
to theTestResponse
. #44658Edit: I've removed the ability to use named methods on the response factory, as we would have to handle standard responses, JSON responses, streamed responses, etc., and that feels like a lot.