Skip to main content

State API

DrevOps\BehatSteps\Steps\Drupal\StateTrait - Source, Example, Helpers

Manage and assert Drupal State API values with automatic revert.

Provides set, delete, and assertion steps for keys in the site's state key-value store. Touched keys are snapshotted on first access and reverted after the scenario finishes.

Skip the revert with @behat-steps-skip:StateTrait. The snapshot registry is cleared unconditionally before and after the scenario, so no snapshot persists across scenarios.

Options​

OptionTypeDefaultTagDescription
state.enabledbooleanTRUE@behat-steps-skip:StateTraitRestore the state values a scenario changed once it finishes.

Steps​

@Given the state :name has the value :value

Set a Drupal state value

Given the state "my_module.launched" has the value "1"
@Given the state :name does not exist

Delete a Drupal state value

Given the state "my_module.launched" does not exist
@Given the following state values exist:

Set multiple Drupal state values from a table

Given the following state values exist:
| name | value |
| my_module.launched | 1 |
| my_module.feature_flag | 0 |
@Then the state :name should have the value :value

Assert that a Drupal state value equals an expected value

Then the state "my_module.launched" should have the value "1"
@Then the state :name should not exist

Assert that a Drupal state key does not exist

Then the state "my_module.launched" should not exist