[7.x] Add ArrayAccess support for Http client get requests - #32401
Merged
Conversation
Member
|
@dmason30 probably best to explain why this is needed, not just link to an issue. |
Contributor
Author
|
@driesvints Thanks done as requested. |
kieraninnes
pushed a commit
to tootootltd/azure-text-analytics
that referenced
this pull request
Jun 24, 2020
…se we need ArrayAccess support for Http client in our tests - @see: laravel/framework#32401 for more info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #32398.
TL;DR
Fixes an
Undefined index: Content-Typeexception and allows access to get request params via array access$request['foo']and in turn allows you to make assertions such as$request['foo'] === 'bar'.Description:
I was writing a test similar to the below and when running it was greeted with an
ErrorExceptionofUndefined index: Content-Type.Cause
Looking at the line causing the error it seems it just needs to check if the key it is searching for exists in the headers array before trying to access it:
Illuminate/Http/Client/Request.php:
Initial fix & New error found
So I initially set out to fix
hasHeaderso that it checks the$keyexists in thearrayreturned by$this->headers()and I ran the tests and got the same errorUndefined index: Content-Typebut from a different location:Illuminate/Http/Client/Request.php:
Adding ArrayAccess Support
I then added
Arr::getcheck in theheader($key)method and then discovered that there is not any existing support for accessing get query parameters via$requestand was met with anotherUndefined index: fooin the below test:So this change gets the query parameters either from
$options['query']or by extracting them from the$url. It handles the below with the tests adjusted to prove it.Then you can do assertions on the
$requestdata: