Skip to content
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

Fix | Resolve headers with array as value #433

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Conversation

smithbm2316
Copy link
Contributor

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 the defineSensitiveHeaders() 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 the src/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 an int 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 my vendor 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

image

JSON response blob
{
    "statusCode": 200,
    "headers": {
        "Date": "null",
        "Content-Type": "application/json; charset=utf-8",
        "Transfer-Encoding": "chunked",
        "Connection": "keep-alive",
        "X-Sorting-Hat-PodId": "null",
        "X-Sorting-Hat-ShopId": "null",
        "X-Storefront-Renderer-Rendered": "null",
        "Vary": [
            "Accept-Encoding",
            "Accept"
        ],
        "x-frame-options": "DENY",
        "content-security-policy": "block-all-mixed-content; frame-ancestors 'none'; upgrade-insecure-requests;",
        "access-control-allow-origin": "*",
        "x-shopify-api-version": "null",
        "x-cache": "hit, server",
        "x-shopid": "null",
        "x-shardid": "null",
        "content-language": "en",
        "powered-by": "Shopify",
        "server-timing": [
            "ipv6"
        ],
        "x-dc": "null",
        "x-request-id": "null",
        "CF-Cache-Status": "DYNAMIC",
        "Report-To": "null",
        "NEL": "null",
        "X-XSS-Protection": "1; mode=block",
        "X-Content-Type-Options": "nosniff",
        "X-Permitted-Cross-Domain-Policies": "none",
        "X-Download-Options": "noopen",
        "Server": "cloudflare",
        "CF-RAY": "null",
        "alt-svc": "h3=\":443\"; ma=86400"
    },
    "data": "{\"data\":{\"collection\":{\"products\":{\"nodes\":[{\"handle\":\"guatemala\",\"title\":\"Guatemala\",\"featuredImage\":{\"url\":\"https://cdn.shopify.com/s/files/1/0704/1322/2107/files/summer-solstice.jpg?v=1718145615\",\"altText\":null,\"height\":500,\"width\":500},\"variantBySelectedOptions\":{\"price\":{\"amount\":\"30.0\",\"currencyCode\":\"USD\"}}},{\"handle\":\"bolivia\",\"title\":\"Bolivia\",\"featuredImage\":{\"url\":\"https://cdn.shopify.com/s/files/1/0704/1322/2107/files/summer-solstice.jpg?v=1718145615\",\"altText\":null,\"height\":500,\"width\":500},\"variantBySelectedOptions\":{\"price\":{\"amount\":\"21.0\",\"currencyCode\":\"USD\"}}},{\"handle\":\"solstice-blend\",\"title\":\"Summer Solstice\",\"featuredImage\":{\"url\":\"https://cdn.shopify.com/s/files/1/0704/1322/2107/files/summer-solstice.jpg?v=1718145615\",\"altText\":null,\"height\":500,\"width\":500},\"variantBySelectedOptions\":{\"price\":{\"amount\":\"22.0\",\"currencyCode\":\"USD\"}}}]}}}}"
}

Copy link
Member

@Sammyjo20 Sammyjo20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix and I appreciate the kind words, good luck with your PHP journey!

@Sammyjo20 Sammyjo20 changed the title fix: resolve headers with array as value Fix | Resolve headers with array as value Jun 26, 2024
@Sammyjo20 Sammyjo20 merged commit 113332a into saloonphp:v3 Jun 26, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants