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/tree/master/tests#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 $process from CliTestTrait

Methods

string
getOutputRaw()

Accessor for the last output, non-trimmed.

string
getErrorOutputRaw()

Accessor for the last stderr output, non-trimmed.

getSimplifiedOutput()

Get command output and simplify away things like full paths and extra whitespace.

string
getSimplifiedErrorOutput()

Returns a simplified version of the error output to facilitate testing.

string
simplifyOutput(string $output)

Remove things like full paths and extra whitespace from the given string.

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.

object
getOutputFromJSON(string $key = null)

Accessor for the last output, decoded from json.

execute(string $command, integer $expected_return = 0, sting $cd = null, array $env = null, string $input = null)

Actually runs the command.

static 
escapeshellarg($arg)

No description

static 
isWindows()

No description

static 
_escapeshellargWindows($arg)

No description

string
buildProcessMessage()

Borrowed from \Symfony\Component\Process\Exception\ProcessTimedOutException

assertOutputEquals(string $expected, string $filter = '')

Checks that the output matches the expected output.

assertErrorOutputEquals(string $expected, string $filter = '')

Checks that the error output matches the expected output.

string
getPathToDrush()

No description

drush(command $command, array $args = [], array $options = [], $site_specification = null, $cd = null, $expected_return = 0, $suffix = null, array $env = [])

Invoke drush in via execute().

string
convertKeyValueToFlag(string $key, string $value)

Given an option key / value pair, convert to a "--key=value" string.

string
drushMajorVersion()

Return the major version of Drush

Details

abstract string getOutputRaw()

Accessor for the last output, non-trimmed.

Return Value

string Raw output as text.

abstract string getErrorOutputRaw()

Accessor for the last stderr output, non-trimmed.

Return Value

string Raw stderr as text.

protected getSimplifiedOutput()

Get command output and simplify away things like full paths and extra whitespace.

protected string getSimplifiedErrorOutput()

Returns a simplified version of the error output to facilitate testing.

Return Value

string A simplified version of the error output that has things like full paths and superfluous whitespace removed from it.

protected string simplifyOutput(string $output)

Remove things like full paths and extra whitespace from the given string.

Parameters

string $output The output string to simplify.

Return Value

string The simplified output.

pathsToSimplify()

string getOutput()

Accessor for the last output, trimmed.

Return Value

string Trimmed output as text.

string getErrorOutput()

Accessor for the last stderr output, trimmed.

Return Value

string Trimmed stderr as text.

array getOutputAsList()

Accessor for the last output, rtrimmed and split on newlines.

Return Value

array Output as array of lines.

array getErrorOutputAsList()

Accessor for the last stderr output, rtrimmed and split on newlines.

Return Value

array Stderr as array of lines.

object getOutputFromJSON(string $key = null)

Accessor for the last output, decoded from json.

Parameters

string $key Optionally return only a top level element from the json object.

Return Value

object Decoded object.

execute(string $command, integer $expected_return = 0, sting $cd = null, array $env = null, string $input = null)

Actually runs the command.

Parameters

string $command The actual command line to run.
integer $expected_return The return code to expect
sting $cd cd The directory to run the command in.
array $env Extra environment variables.
string $input A string representing the STDIN that is piped to the command.

static escapeshellarg($arg)

Parameters

$arg

static isWindows()

static _escapeshellargWindows($arg)

Parameters

$arg

string buildProcessMessage()

Borrowed from \Symfony\Component\Process\Exception\ProcessTimedOutException

Return Value

string

protected 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.

Parameters

string $expected The expected output.
string $filter Optional regular expression that should be ignored in the error output.

protected 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.

Parameters

string $expected The expected output.
string $filter Optional regular expression that should be ignored in the error output.

string getPathToDrush()

Return Value

string

drush(command $command, array $args = [], array $options = [], $site_specification = null, $cd = null, $expected_return = 0, $suffix = null, array $env = [])

Invoke drush in via execute().

Parameters

command $command A defined drush command such as 'cron', 'status' or any of the available ones such as 'drush pm'.
array $args Command arguments.
array $options An associative array containing options.
$site_specification A site alias or site specification. Include the '@' at start of a site alias.
$cd A directory to change into before executing.
$expected_return The expected exit code, e.g. 0 or 1 or some other expected value.
$suffix Any code to append to the command. For example, redirection like 2>&1.
array $env Environment variables to pass along to the subprocess.

protected string convertKeyValueToFlag(string $key, string $value)

Given an option key / value pair, convert to a "--key=value" string.

Parameters

string $key The option name
string $value The option value (or empty)

Return Value

string

string drushMajorVersion()

Return the major version of Drush

Return Value

string e.g. "8" or "9"