final class PHPUnitRunner extends TestRunner

Supports PHPUnit testing operations.

Constants

ALLOWED_OPTIONS

The array of options allowed as input for the test command.

FEATURE_PATH

The path for feature tests.

TEST_COMMAND

The command for PHPUnit

TEST_FILE_EXTENSION

File extension for PHPUnit unit tests.

UNIT_PATH

The path for unit tests.

Properties

protected string $inputOptions

A string of input options provided as input when running the test command.

from  TestRunner
protected OutputInterface $output

The Symfony OutputInterface object.

from  TestRunner

Methods

__construct(InputInterface $input, OutputInterface $output)

Constructor

bool
areAllSuitesEmpty(array $testSuites)

Test to ensure there is not an empty test suite.

int
allTests(array $testSuites, string|array $extensions, string $testCommand)

Performs all available tests.

static void
duplicateTestNameMessage()

Present message to the user if the following conditions are true:

  • Test case files in multiple suites with the same name
  • There exists a function in both classes with the same name

static array
getAllTestsInSuite(string $path, string $ext)

Retrieves all files in test suite so they can be run.

void
noAvailableTestsMessage()

Alerts use if there are no available tests to perform.

void
runTest(string $test, string $testCommand)

Runs the unit test for your testing suite.

int
selectByTestName(string $testArg, array $testSuites, string|array $extensions, string $testCommand)

Supports ability to run test by class/file name.

int
singleFileWithinSuite(string $testArg, string $testSuite, string $ext, string $command)

Performs testing against a single class within a test suite.

static bool
testExists(string $name, array $testSuites, string|array $extensions)

Determine if test file exists in any of the available test suites.

static bool
testIfSame(string $name, array $testSuites, string|array $extension)

Enforces rule that classes/files across test suites should be unique for filtering.

int
testSuite(array $collection, string $testCommand)

Run all test files in an individual test suite.

static bool
testSuiteStatus(array $suiteStatuses)

Determines if execution of a test suite(s) is successful. The result is determined by testing if the status value is set and its integer value is equal to Command::SUCCESS.

static bool
verifyFilterSyntax(string $testArg)

Ensure filter syntax is correct. Does not test if only one : is in string.

static string
parseOptions(InputInterface $input)

Parses PHPUnit related arguments and ignore Symfony arguments.

int
testByFilter(string $testArg, array $testSuites, string $extension)

Run filtered test by function name.

Details

at line 63
__construct(InputInterface $input, OutputInterface $output)

Constructor

Parameters

InputInterface $input

The Symfony InputInterface object.

OutputInterface $output

The Symfony OutputInterface object.

in TestRunner at line 51
bool areAllSuitesEmpty(array $testSuites)

Test to ensure there is not an empty test suite.

Parameters

array $testSuites

The collection of all available test suites. Best practice is to use const provided by child class.

Return Value

bool

True if all test suites are empty. Otherwise, we return false.

in TestRunner at line 67
int allTests(array $testSuites, string|array $extensions, string $testCommand)

Performs all available tests.

Parameters

array $testSuites

An array of test suite paths. Best practice is to use const provided by child class.

string|array $extensions

A string or an array of supported file extensions. Best practice is to use const provided by child class.

string $testCommand

The command for running the tests.

Return Value

int

A value that indicates success, invalid, or failure.

in TestRunner at line 107
static private void duplicateTestNameMessage()

Present message to the user if the following conditions are true:

  • Test case files in multiple suites with the same name
  • There exists a function in both classes with the same name

This function is called internally by the selectTest function.

Return Value

void

in TestRunner at line 121
static array getAllTestsInSuite(string $path, string $ext)

Retrieves all files in test suite so they can be run.

Parameters

string $path

Path to test suite.

string $ext

File extension to specify between php and js related tests. Best practice is to use const provided by child class.

Return Value

array

The array of all filenames in a particular directory.

in TestRunner at line 130
private void noAvailableTestsMessage()

Alerts use if there are no available tests to perform.

Return Value

void

in TestRunner at line 141
void runTest(string $test, string $testCommand)

Runs the unit test for your testing suite.

Parameters

string $test

The test to be performed.

string $testCommand

The test command to be executed.

Return Value

void

in TestRunner at line 158
int selectByTestName(string $testArg, array $testSuites, string|array $extensions, string $testCommand)

Supports ability to run test by class/file name.

Parameters

string $testArg

The name of the class/file.

array $testSuites

An array of test suite paths. Best practice is to use const provided by child class.

string|array $extensions

A string or an array of supported file extensions. Best practice is to use const provided by child class.

string $testCommand

The command for running the tests.

Return Value

int

A value that indicates success, invalid, or failure.

in TestRunner at line 204
int singleFileWithinSuite(string $testArg, string $testSuite, string $ext, string $command)

Performs testing against a single class within a test suite.

Parameters

string $testArg

The name of the test file without extension.

string $testSuite

The name of the test suite. Best practice is to use const provided by child class.

string $ext

The file extension. Best practice is to use const provided by child class.

string $command

The test command. Best practice is to use const provided by child class.

Return Value

int

A value that indicates success, invalid, or failure.

in TestRunner at line 223
static bool testExists(string $name, array $testSuites, string|array $extensions)

Determine if test file exists in any of the available test suites.

Parameters

string $name

The name of the test we want to confirm if it exists.

array $testSuites

The array of test suites. Best practice is to use const provided by child class.

string|array $extensions

A string or an array of supported file extensions. Best practice is to use const provided by child class.

Return Value

bool

True if test does exist. Otherwise, we return false.

in TestRunner at line 252
static bool testIfSame(string $name, array $testSuites, string|array $extension)

Enforces rule that classes/files across test suites should be unique for filtering.

Parameters

string $name

name of the test class to be executed.

array $testSuites

The array of test suites. Best practice is to use const provided by child class.

string|array $extension

A string or an array of supported file extensions. Best practice is to use const provided by child class.

Return Value

bool

True if the class or file name exists in multiple test suites. Otherwise, we return false.

in TestRunner at line 283
int testSuite(array $collection, string $testCommand)

Run all test files in an individual test suite.

Parameters

array $collection

All classes in a particular test suite.

string $testCommand

The test command to be executed.

Return Value

int

A value that indicates success, invalid, or failure.

in TestRunner at line 305
static bool testSuiteStatus(array $suiteStatuses)

Determines if execution of a test suite(s) is successful. The result is determined by testing if the status value is set and its integer value is equal to Command::SUCCESS.

Parameters

array $suiteStatuses

Array of integers that indicates a test is successful.

Return Value

bool

True if execution is successful. Otherwise, we return false.

in TestRunner at line 318
static bool verifyFilterSyntax(string $testArg)

Ensure filter syntax is correct. Does not test if only one : is in string.

Parameters

string $testArg

The name of the test file with filter.

Return Value

bool

True if filter syntax is correct. Otherwise, we return false.

at line 75
static string parseOptions(InputInterface $input)

Parses PHPUnit related arguments and ignore Symfony arguments.

Parameters

InputInterface $input

Instance of InputInterface from command.

Return Value

string

A string containing the arguments to be provided to PHPUnit.

at line 150
int testByFilter(string $testArg, array $testSuites, string $extension)

Run filtered test by function name.

Parameters

string $testArg

The name of the class.

array $testSuites

An array of test suite paths.

string $extension

Return Value

int

A value that indicates success, invalid, or failure.