pact-foundation / pact-php

PHP version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project
Apache License 2.0
273 stars 92 forks source link

feat: Allow to build multiple interactions #508

Closed tienvx closed 8 months ago

tienvx commented 8 months ago

This is how end-user use it:

$builder = new InteractionBuilder($config);
$builder
       ->given('a person exists')
       ->uponReceiving('a get request to /hello/{name}')
       ->with($request)
       ->willRespondWith($response, false);
$builder
       ->newInteraction()
       ->given('a person exists')
       ->uponReceiving('a get request to /goodbye/{name}')
       ->with($request)
       ->willRespondWith($response);

If not using this feature (nothing change):

$builder = new InteractionBuilder($config);
$builder
       ->given('a person exists')
       ->uponReceiving('a get request to /hello/{name}')
       ->with($request)
       ->willRespondWith($response);
individual-it commented 3 months ago

@tienvx hi, I'm just trying this, but how can your example work as newInteraction() returns void?

mefellows commented 3 months ago

Will leave this to Tien to answer, but nice to see you 'round these parts again Artur!

individual-it commented 3 months ago

Yea, I'm around again because I'm currently updating pact-php from 7.1 to 10.0.0-beta2 because I need tests where APIs return real binary data not just JSON. That is all solved and also newInteraction() works. Just need to do:

$builder->newInteraction();
$builder
    ->uponReceiving('a POST request to renew token')
...

and every interaction, except of the last one, needs false in the second parameter of willRespondWith see: https://github.com/nextcloud/integration_openproject/pull/666

Maybe I will find time to document that

individual-it commented 3 months ago

The documentation is in https://github.com/pact-foundation/pact-php/pull/620 please review

And thank-you for this great feature! I really should not have started with complains