pact-php icon indicating copy to clipboard operation
pact-php copied to clipboard

Pact-PHP <=9.x.x - Various thoughts on the READme from a Pact and PHP newbie

Open Grunet opened this issue 4 years ago • 0 comments

I tried using pact-php for the first time and ran into some difficulties getting things setup

TL;DR

I was tasked with migrating my work codebase off of Guzzle v3 and up to Guzzle v6, and eventually realized pact-php could help me do this safely by writing tests through Guzzle and mocking the API responses. For the moment I wasn't planning on using the provider/contract testing functionality.

As I was trying to get started using it (primarily via the READme) I ran into some difficulties, listed below in rough order of how confused I was when I encountered them

  1. The READme never mentions "HealthCheckTimeout" and "HealthCheckRetrySec", but both seem required to be set (via their setters) in order to avoid a type error (like "must be of the type int, null returned") when they're retrieved (this seems to be a new error as of PHP 7 maybe?). I also wasn't sure what their default values should be (ended up going with a max of 20 retries 1 second apart)
    • See https://gitpod.io/#https://github.com/Grunet/pact-php-readme-repros/tree/health-checks for a reproduction
  2. Blindly copy-pasting snippets one after the other from the READme in the order they're presented eventually leads to a situation where the server was stopped, but an interaction is built afterwards. The error message that results didn't make it super clear to me what I had done wrong (I also hit this again when trying to create a reproduction for the first time)
    • Just explicitly leaving a comment block in-between $server->start() and $server-stop() indicating that's where the remaining code should be filled in I think would've been nice
    • See https://gitpod.io/#https://github.com/Grunet/pact-php-readme-repros/tree/interaction-after-stopped for a reproduction
  3. Some of the code snippets in the READme I was copy-pasting from don't include the relevant "use" directives, so once I realized the issue I had to go look in the linked example file to find them
  4. The "setCors" method included in the READme doesn't seem to do anything if it's unset, set to true, or set to false. Since there's no browser in play i was fairly confused about what this was for
    • See https://gitpod.io/#https://github.com/Grunet/pact-php-readme-repros/tree/setcors for a reproduction
  5. The "Build an Interaction" section of the READme includes a "given" method call that isn't present in the sample file

Let me know if I can help clarify any of this or if I should split things into individual issues.

Thank you all for your work on pact-php and for considering this feedback!

Grunet avatar Aug 15 '21 03:08 Grunet