DrushTestTrait
trait DrushTestTrait (View source)
DrushTestTrait provides a drush()
method that may be
used to write functional tests for Drush extensions.
More information is available at https://github.com/drush-ops/drush/blob/13.x/docs/contribute/unish.md#drush-test-traits.
Traits
CliTestTrait provides an execute()
method that is useful
for launching executable programs in functional tests.
OutputUtilsTrait provides some useful utility methods for test classes
that define getOutputRaw()
and getErrorOutputRaw()
methods.
Properties
protected int | $timeout | Timeout for command. |
from CliTestTrait |
protected int | $idleTimeout | Idle timeouts for commands. |
from CliTestTrait |
protected Process|null | $process | from CliTestTrait |
Methods
Get command output and simplify things like full paths and extra whitespace.
Returns a simplified version of the error output to facilitate testing.
Remove things like full paths and extra whitespace from the given string.
Accessor for the last output, rtrimmed and split on newlines.
Accessor for the last stderr output, rtrimmed and split on newlines.
Accessor for the last output, decoded from json.
Run a command and return the process without waiting for it to finish.
Actually runs the command.
Borrowed from \Symfony\Component\Process\Exception\ProcessTimedOutException
Checks that the output matches the expected output.
Checks that the error output matches the expected output.
No description
Invoke drush in via execute().
Given an option key / value pair, convert to a "--key=value" string.
Return the major version of Drush
Details
abstract string
getOutputRaw()
Accessor for the last output, non-trimmed.
abstract string
getErrorOutputRaw()
Accessor for the last stderr output, non-trimmed.
protected string
getSimplifiedOutput()
Get command output and simplify things like full paths and extra whitespace.
protected string
getSimplifiedErrorOutput()
Returns a simplified version of the error output to facilitate testing.
protected string
simplifyOutput(string $output)
Remove things like full paths and extra whitespace from the given string.
array
pathsToSimplify()
No description
string
getOutput()
Accessor for the last output, trimmed.
string
getErrorOutput()
Accessor for the last stderr output, trimmed.
array
getOutputAsList()
Accessor for the last output, rtrimmed and split on newlines.
array
getErrorOutputAsList()
Accessor for the last stderr output, rtrimmed and split on newlines.
mixed
getOutputFromJSON(string|int|null $key = null)
Accessor for the last output, decoded from json.
Process
startExecute(string|array $command, string|null $cd = null, array|null $env = null, string|null $input = null)
Run a command and return the process without waiting for it to finish.
void
execute(array|string $command, int $expected_return = 0, string|null $cd = null, array|null $env = null, string|null $input = null)
Actually runs the command.
static string
escapeshellarg(string $arg)
No description
static bool
isWindows()
No description
static string
_escapeshellargWindows(string $arg)
No description
string
buildProcessMessage()
Borrowed from \Symfony\Component\Process\Exception\ProcessTimedOutException
protected void
assertOutputEquals(string $expected, string $filter = '')
Checks that the output matches the expected output.
This matches against a simplified version of the actual output that has absolute paths and duplicate whitespace removed, to avoid false negatives on minor differences.
protected void
assertErrorOutputEquals(string $expected, string $filter = '')
Checks that the error output matches the expected output.
This matches against a simplified version of the actual output that has absolute paths and duplicate whitespace removed, to avoid false negatives on minor differences.
string
getPathToDrush()
No description
void
drush($command, array $args = [], array $options = [], string|null $site_specification = null, string|null $cd = null, int $expected_return = 0, string|null $suffix = null, array $env = [])
Invoke drush in via execute().
protected string
convertKeyValueToFlag(string $key, mixed $value)
Given an option key / value pair, convert to a "--key=value" string.
int
drushMajorVersion()
Return the major version of Drush