pact-php
pact-php copied to clipboard
Proposal to add features to work with provider state
I can try to do pull request with feature to work with provider state like the gherkin language work's (http://behat.org/en/latest/user_guide/gherkin.html). The main idea to map some state context to literal string state from consumer expectation.
The code that load provider state may be similar to
$stateMatcher = new StateMatcher()
$stateMatcher->addStateContext(new StateContext());
$this->stateMatcher->load('User with id 223 and default data');
/**
* Load method signature
* @param string $providerState
* @param string $stateDelimiter
*/
public function load(string $providerState, $stateDelimiter = 'And')
{
class StateContext implements StateContextInterface
{
/**
* @Given(name="/User with id (\d+)/")
*/
public function methodThatLoadStateForUser(int $id)
{
}
/**
* @Given(name="/Another step/")
*/
public function methodWithAnotherState()
{
}
}
And this mechanism can be compatible with pact v3 specification too after some refinement.
Syntax of methods that load state can be one of this:
/**
* @Given(name="/Another step/", consumer={"MyConsumer", "AnotherConsumer"})
*/
public function methodWithAnotherState()
{
}
or
/**
* @Given /Another step/
*/
public function methodWithAnotherState()
{
}
Is this good idea?
The idea is not clear? :)
I can check in about a week
On Mon, Jun 11, 2018, 1:17 AM arkonchik [email protected] wrote:
The idea is not clear? :)
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-php/issues/77#issuecomment-396145539, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZX6KfVTYsmcfzYJub3qzth907Ys4mHks5t7hl8gaJpZM4UcJWP .
Reading your description, I think this would be a good approach to handling state. That way we can map this idea back to the setProviderState description. Moving from Php Pact 2.0 to Php Pact 3.x, we now make web calls to the Ruby backend (I am sure you realize this at this point). In that move, I think Php lost a little bit of control over states. Anything that can help clarify this would be a good thing.