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 set interaction key for v4 #503

Closed tienvx closed 8 months ago

tienvx commented 8 months ago

I'm not sure:

So I invented 3 methods in builder:

 $config = new MockServerConfig();
$config->setPactSpecificationVersion('4.0.0');
$builder = new InteractionBuilder($config);
$builder
    ->key('key')
    ->pending(true) // other PR
    ->comments(['key' => 'value']) // other PR
    ->given('Get Goodbye')
    ->uponReceiving('A get request to /goodbye/{name}')
    ->with($request)
    ->willRespondWith($response);

Is this okay?

Should I change to setKey, setPending setComments? Should I change to withKey, withPending, withComments ?

What do you think? cc @YOU54F @JP-Ellis

JP-Ellis commented 8 months ago

I think the convention of prefixing methods with set or with or nothing is really up to you and what makes most sense in the language.

For example, languages that allow overloading of functions might have the same function as both the setter and getter based on the presence of an argument. Whereas languages which do not support this might instead have separate functions. You should follow what makes most sense for PHP.

In Python, I'm also considering having a clear nomenclature to distinguish whether the pact is being modified or the specific interaction. I haven't settled yet on the nomenclature yet though.