Download the PHP package gorghoa/scenariostate-behat-extension without Composer
On this page you can find all versions of the php package gorghoa/scenariostate-behat-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gorghoa/scenariostate-behat-extension
More information about gorghoa/scenariostate-behat-extension
Files in gorghoa/scenariostate-behat-extension
Package scenariostate-behat-extension
Short Description Scenario shared state extension for Behat
License MIT
Informations about the package scenariostate-behat-extension
ScenarioStateBehatExtension
:warning: This projet is not maintained anymore. Still, anyone interested to take over is welcome to do so :).
When to use
Behat scenarios are all about state. First you put the system under test
to a special state through the Given
steps. Then you continue to manipulate
your system through When
steps and finally testing the resulting state via
the Then
steps.
When testing a system like a single page app or a stateful website, the resulting state of our steps is handled by the system itself (either by the browser, or by the php session, etc.).
But, when you are testing a stateless system, chiefly an API, then the resulting state of our steps is handled by no one. This is the case for this extension.
Installation
Then update your project's behat.yml
config file by loading the extension:
Usage
This behat extension will allow scenarios steps to provide and consume what I call "fragments" of the resulting state.
Each scenario get it's own isolated and unique state.
Let's say a feature like this:
See the "this banana"? What we want during the second step execution is a reference to the exact banana the bonobo initially took. This behat extension will help us to propagate the banana refence amongst steps.
Provide state fragment
To share a piece of state with all other scenario's steps, your contexts need to implement the
Gorghoa\ScenarioStateBehatExtension\Context\ScenarioStateAwareContext
interface.
This interface declares one method to implement: public function setScenarioState(ScenarioStateInterface $scenarioState)
which can be imported using ScenarioStateAwareTrait
. This ScenarioState is responsible for storing your state.
Then you can publish state fragment through the ScenarioStateInterface::provideStateFragment(string $key, mixed $value)
method.
Consuming state fragments
To consume state fragments provided to the scenario's state, you must add needed arguments to step's methods using
ScenarioStateArgument
annotation. It can be used easily:
- inject argument from store with the exact same name:
@ScenarioStateArgument("scenarioBanana")
or@ScenarioStateArgument(name="scenarioBanana")
- inject argument from store changing its name:
@ScenarioStateArgument(name="scenarioBanana", argument="banana")
Using state fragments in Behat hook methods
It's also possible to consume state fragments in hook methods: BeforeScenario
& AfterScenario
. And much better,
the order is not important, you can set your arguments in any order you want:
Why injecting state's fragments through method params
- Clear dependencies declaration for the step method
- Runtime checks by php: fail quickly if the argument is not present or does not match type hint
- The less verbose way of consuming shared scenario state
All versions of scenariostate-behat-extension with dependencies
behat/behat Version ^3.0.12
symfony/dependency-injection Version ^2.7|^3.0|^4.0|^5.0
symfony/process Version ^2.0|^3.0|^4.0|^5.0
doctrine/annotations Version ^1.2