System time
DrevOps\BehatSteps\Steps\Drupal\TimeTrait - Source, Example
Control system time in tests using Drupal state overrides.
This trait requires the consuming application to use a mockable time service that checks Drupal state for time overrides.
Example implementation:
- Time service: https://github.com/drevops/behat-steps/blob/main/tests/behat/fixtures_drupal/d11/web/modules/custom/mysite_core/src/Time/Time.php
- Time interface: https://github.com/drevops/behat-steps/blob/main/tests/behat/fixtures_drupal/d11/web/modules/custom/mysite_core/src/Time/TimeInterface.php
- Service registration: https://github.com/drevops/behat-steps/blob/main/tests/behat/fixtures_drupal/d11/web/modules/custom/mysite_core/mysite_core.services.yml
Skip processing with tag:
@behat-steps-skip:TimeTrait.
Prerequisites
| Prerequisite | Capability |
|---|---|
| A backend in the scenario's list provides "StateCapabilityInterface" | StateCapabilityInterface |
Options
| Option | Type | Default | Tag | Description |
|---|---|---|---|---|
time.enabled | boolean | TRUE | @behat-steps-skip:TimeTrait | Restore the site clock after a scenario that moved it. |
Steps
@When the system time is set to :value
Sets the system time for testing
When the system time is set to "1737849900"
@When the system time is reset
Resets the system time to real time
When the system time is reset