Hello :wave: I'm trying to setup provider states u...
# pact-php
a
Hello 👋 I'm trying to setup provider states using the
--provider-states-setup-url
option. However, on the endpoint I configured, I'm receiving a
null
state This is what my endpoint is receiving:
Copy code
{
  "body": {
    "consumer": "ms.pact-consumer-example-for-php",
    "state": null,
    "states": [
      null
    ],
    "params": []
  }
}
heres the pact file i'm fetching from the broker:
Copy code
{
  "consumer": {
    "name": "ms.pact-consumer-example-for-php"
  },
  "provider": {
    "name": "ms.pact-provider-example-for-php"
  },
  "interactions": [
    {
      "description": "A request for a product",
      "providerState": "A produƒct with id c931b702-f48a-447c-8619-80556f40e82b exists",
      "request": {
        "method": "GET",
        "path": "/api/v1/products/c931b702-f48a-447c-8619-80556f40e82b",
        "headers": {
          "Content-Type": "application/json"
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json"
        },
        "body": {
          "id": "c931b702-f48a-447c-8619-80556f40e82b",
          "name": "Drill",
          "brand": "Makita"
        },
        "matchingRules": {
          "$.body.id": {
            "match": "regex",
            "regex": "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$"
          },
          "$.body.name": {
            "match": "type"
          },
          "$.body.brand": {
            "match": "type"
          }
        }
      }
    },
    {
      "description": "A request for a product",
      "providerState": "There is no product with id 9b40cb15-dfcf-496f-9ba2-208312a25527",
      "request": {
        "method": "GET",
        "path": "/api/v1/products/9b40cb15-dfcf-496f-9ba2-208312a25527",
        "headers": {
          "Content-Type": "application/json"
        }
      },
      "response": {
        "status": 404,
        "headers": {
          "Content-Type": "application/json"
        },
        "body": {
          "error": {
            "message": "The product with id \"9b40cb15-dfcf-496f-9ba2-208312a25527\" does not exists",
            "app_code": "PRODUCT_NOT_FOUND"
          }
        },
        "matchingRules": {
          "$.body.error.message": {
            "match": "type"
          },
          "$.body.error.app_code": {
            "match": "type"
          }
        }
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    }
  }
}
y
Hey buddy, I don't believe pact-php supports v3.0.0 spec of the pact-specification https://github.com/pact-foundation/pact-php#specifications it may be a red herring, but food for thought
🤔 Hmm so the pact-verifier functionality in pact-php https://github.com/pact-foundation/pact-php#provider-verification uses the ruby standalone verifier https://github.com/pact-foundation/pact-provider-verifier Looking at that readme, that should support v3 https://github.com/pact-foundation/pact-provider-verifier#pact-specification-v3-provider-state-support That is part of a larger section of verification of provider states in the readme https://github.com/pact-foundation/pact-provider-verifier#api-with-provider-states You could try
providerStates
with a v2 pact spec and see if that resolves it, and if so I would assume there is some work in PHP, if not it will be something else 👍
a
Thanks for your help @Yousaf Nabi (pactflow.io),it was a spec version issue 👏 I regenerated the pact file using
2.0.0
on the consumer side, and now i'm receiving this body in my setup endpoint
Copy code
{
  "body": {
    "consumer": "ms.pact-consumer-example-for-php",
    "state": "A product with id c931b702-f48a-447c-8619-80556f40e82b exists",
    "states": [
      "A product with id c931b702-f48a-447c-8619-80556f40e82b exists"
    ],
    "params": []
  }
}
I assume that I should use the
state
key instead of the
states
one ?
y
awesome! Aye I think based on the comment below, that states should be ignored, inferring use
state
👍
Ignore the
states
array that you will see if you happen to print out the live provider state set up request body
Good luck in your pact Journey buddy!
loveparrot 2