Skip to main content

Drush

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

Run Drush commands and assert their output.

  • Run a command with or without arguments, through the Drush backend.
  • Run a command that is expected to fail and keep its output.
  • Assert the last command's output by substring or regular expression.

Steps resolve the backend that can run Drush commands, not the first one in the scenario's order. They work in a scenario driven by any other backend as long as the suite lists a Drush-capable one.

Steps​

@When I run the drush command :command

Run a Drush command

When I run the drush command "status"
When I run the drush command "config:get system.site name"
@When I run the drush command :command with the arguments :arguments

Run a Drush command with arguments

When I run the drush command "pm:list" with the arguments "--status=enabled"
When I run the drush command "config:get" with the arguments "system.site uuid"
@When I run the failing drush command :command

Run a Drush command that is expected to fail

When I run the failing drush command "pm:uninstall no_such_module"
@When I run the failing drush command :command with the arguments :arguments

Run a Drush command with arguments that is expected to fail

When I run the failing drush command "pm:uninstall" with the arguments "no_such_module"
@When I print the last drush output

Print the output of the most recent Drush command

When I print the last drush output
@Then the drush output should contain :value

Assert that the last Drush output contains the text

Then the drush output should contain "Drupal version"
@Then the drush output should not contain :value

Assert that the last Drush output does not contain the text

Then the drush output should not contain "error"
@Then the drush output should match :pattern

Assert that the last Drush output matches the pattern

Then the drush output should match "/Drupal [0-9]+/"