class Command (View source)

A TestRunner for the Command Line Interface (CLI) PHP SAPI Module.

Properties

protected array $arguments
protected array $options
protected array $longOptions

Methods

static 
main(bool $exit = true)

No description

int
run(array $argv, bool $exit = true)

No description

createRunner()

Create a TestRunner, override in subclasses.

handleArguments(array $argv)

Handles the command-line arguments.

handleLoader(string $loaderClass, string $loaderFile = '')

Handles the loading of the PHPUnit\Runner\TestSuiteLoader implementation.

Printer|string|null
handlePrinter(string $printerClass, string $printerFile = '')

Handles the loading of the PHPUnit\Util\Printer implementation.

handleBootstrap(string $filename)

Loads a bootstrap file.

handleVersionCheck()

No description

showHelp()

Show the help message.

handleCustomTestSuite()

Custom callback for test suite discovery.

Details

static main(bool $exit = true)

Parameters

bool $exit

int run(array $argv, bool $exit = true)

Parameters

array $argv
bool $exit

Return Value

int

protected TestRunner createRunner()

Create a TestRunner, override in subclasses.

Return Value

TestRunner

protected handleArguments(array $argv)

Handles the command-line arguments.

A child class of PHPUnit\TextUI\Command can hook into the argument parsing by adding the switch(es) to the $longOptions array and point to a callback method that handles the switch(es) in the child class like this

<?php class MyCommand extends PHPUnit\TextUI\Command { public function __construct() { // my-switch won't accept a value, it's an on/off $this->longOptions['my-switch'] = 'myHandler'; // my-secondswitch will accept a value - note the equals sign $this->longOptions['my-secondswitch='] = 'myOtherHandler'; }

// --my-switch  -> myHandler()
protected function myHandler()
{
}

// --my-secondswitch foo -> myOtherHandler('foo')
protected function myOtherHandler ($value)
{
}

// You will also need this - the static keyword in the
// PHPUnit\TextUI\Command will mean that it'll be
// PHPUnit\TextUI\Command that gets instantiated,
// not MyCommand
public static function main($exit = true)
{
    $command = new static;

    return $command->run($_SERVER['argv'], $exit);
}

}

Parameters

array $argv

protected TestSuiteLoader|null handleLoader(string $loaderClass, string $loaderFile = '')

Handles the loading of the PHPUnit\Runner\TestSuiteLoader implementation.

Parameters

string $loaderClass
string $loaderFile

Return Value

TestSuiteLoader|null

protected Printer|string|null handlePrinter(string $printerClass, string $printerFile = '')

Handles the loading of the PHPUnit\Util\Printer implementation.

Parameters

string $printerClass
string $printerFile

Return Value

Printer|string|null

protected handleBootstrap(string $filename)

Loads a bootstrap file.

Parameters

string $filename

protected handleVersionCheck()

protected showHelp()

Show the help message.

protected handleCustomTestSuite()

Custom callback for test suite discovery.