class PhpUnitTestRunner implements ContainerInjectionInterface (View source)

Run PHPUnit-based tests.

This class runs PHPUnit-based tests and converts their JUnit results to a format that can be stored in the {simpletest} database schema.

This class is @internal and not considered to be API.

Properties

protected string $workingDirectory

Path to the working directory.

protected string $appRoot

Path to the application root.

Methods

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

__construct(string $app_root, string $working_directory)

Constructs a test runner.

string
xmlLogFilePath(int $test_id)

Returns the path to use for PHPUnit's --log-junit option.

string
phpUnitCommand()

Returns the command to run PHPUnit.

string
runCommand(array $unescaped_test_classnames, string $phpunit_file, int $status = NULL, string[] $output = NULL)

Executes the PHPUnit command.

array
runTests(int $test_id, array $unescaped_test_classnames, int $status = NULL)

Executes PHPUnit tests and returns the results of the run.

int[][]
summarizeResults(array $results)

Tallies test results per test class.

Details

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

__construct(string $app_root, string $working_directory)

Constructs a test runner.

Parameters

string $app_root

Path to the application root.

string $working_directory

Path to the working directory. JUnit log files will be stored in this directory.

string xmlLogFilePath(int $test_id)

internal  
 

Returns the path to use for PHPUnit's --log-junit option.

Parameters

int $test_id

The current test ID.

Return Value

string

Path to the PHPUnit XML file to use for the current $test_id.

string phpUnitCommand()

internal  
 

Returns the command to run PHPUnit.

Return Value

string

The command that can be run through exec().

string runCommand(array $unescaped_test_classnames, string $phpunit_file, int $status = NULL, string[] $output = NULL)

internal  
 

Executes the PHPUnit command.

Parameters

array $unescaped_test_classnames

An array of test class names, including full namespaces, to be passed as a regular expression to PHPUnit's --filter option.

string $phpunit_file

A filepath to use for PHPUnit's --log-junit option.

int $status

(optional) The exit status code of the PHPUnit process will be assigned to this variable.

string[] $output

(optional) The output by running the phpunit command. If provided, this array will contain the lines output by the command.

Return Value

string

The results as returned by exec().

array runTests(int $test_id, array $unescaped_test_classnames, int $status = NULL)

internal  
 

Executes PHPUnit tests and returns the results of the run.

Parameters

int $test_id

The current test ID.

array $unescaped_test_classnames

An array of test class names, including full namespaces, to be passed as a regular expression to PHPUnit's --filter option.

int $status

(optional) The exit status code of the PHPUnit process will be assigned to this variable.

Return Value

array

The parsed results of PHPUnit's JUnit XML output, in the format of {simpletest}'s schema.

int[][] summarizeResults(array $results)

internal  
 

Tallies test results per test class.

Parameters

array $results

Array of results in the {simpletest} schema. Can be the return value of PhpUnitTestRunner::runTests().

Return Value

int[][]

Array of status tallies, keyed by test class name and status type.