Fix | Resolve headers with array as value #433
Merged
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.
Issue that this solves
When using Saloon to request data from Shopify's GraphQL Storefront API, I am using a general
Fixture
to try and replace a bunch of the headers in the response with thedefineSensitiveHeaders()
function to replace those values with"null"
so that I'm not committing sensitive info to my repository. However, I get an error when running my tests using these fixtures, because the recursivelyReplaceAttributes() function in thesrc/Helpers/FixtureHelper.php
file throws an error on headers that have arrays as values while it walks the array of Headers recursively. It seems as though the issue it's having is because it gets anint
as the header's$key
for those headers that are in a regular array, not an associative one. I've implemented a one line fix in this PR that solved the issue for me locally in myvendor
folder, but I am also quite new to PHP so there might be a much more robust solution than the simple type-cast that I did here. Loving using Saloon for wranging my Shopify integration, thanks for all your hard work on this project @Sammyjo20! If you'd like a more detailed reproduction of this, I'd be more than happy to provide one, I just wanted to get this up while I had some time today before I forget exactly what was going wrong.Error message when running tests
JSON response blob