TestsCommand

Class
extends BaseCommand
Final: Yes

Facilitates the execution of the PHPUnit testing framework.

Description

This class MUST NOT be overridden and SHALL configure testing parameters dynamically.

Attributes
#[AsCommand]
$name : 'tests'
$description : 'Runs PHPUnit tests.'
$help : 'This command runs PHPUnit to execute your tests.'

Table of Contents

Interfaces

LoggerAwareCommandInterface

Defines the logger contract consumed by reusable command result helpers.

Constants

 = 'phpunit.xml'

Properties

Methods

 : mixed
addJsonOption()

Adds the standard JSON output options to the current command.

 : static
configure()

Configures the testing command input constraints.

 : void
execute()

Triggers the PHPUnit engine based on resolved paths and settings.

 : int
isJsonOutput()

Determines whether JSON output was requested.

 : bool
isPrettyJsonOutput()

Determines whether pretty JSON output was requested.

 : bool
 : ProcessBuilderInterface, string|null}
failure()

Logs a failed command result and returns the failure exit code.

 : int
notice()

Logs an informational command message at notice level.

 : void
resolvePath()

Safely constructs an absolute path tied to a defined capability option.

 : string
success()

Logs a successful command result and returns the success exit code.

 : int
 : array{int, string, array}
Constants

Constants

CONFIG

Public
public string CONFIG = 'phpunit.xml'

Description

identifies the local configuration file for PHPUnit processes

Properties

$fileLocator

Private Read-only
private FileLocatorInterface $fileLocator

$logger

Private Read-only
private LoggerInterface $logger
Methods

__construct()

Public
public __construct(CoverageSummaryLoaderInterface  $coverageSummaryLoader, ComposerJsonInterface  $composer, FilesystemInterface  $filesystem, FileLocatorInterface  $fileLocator, ProcessBuilderInterface  $processBuilder, ProcessQueueInterface  $processQueue, LoggerInterface  $logger) : mixed
Parameters
$coverageSummaryLoader : CoverageSummaryLoaderInterface

Description

the loader used for coverage-php summaries

$composer : ComposerJsonInterface

Description

the composer.json reader for autoload information

$filesystem : FilesystemInterface

Description

the filesystem utility used for path resolution

$fileLocator : FileLocatorInterface

Description

the file locator used to resolve PHPUnit configuration

$processBuilder : ProcessBuilderInterface

Description

the builder used to assemble the PHPUnit process

$processQueue : ProcessQueueInterface

Description

the queue used to execute PHPUnit

$logger : LoggerInterface

Description

the output-aware logger

addJsonOption()

Protected

Adds the standard JSON output options to the current command.

protected addJsonOption() : static
Return values
static

configure()

Protected

Configures the testing command input constraints.

protected configure() : void

Description

The method MUST specify valid arguments for testing paths, caching directories, bootstrap scripts, and coverage instructions. It SHALL align with robust testing standards.

execute()

Protected

Triggers the PHPUnit engine based on resolved paths and settings.

protected execute(InputInterface  $input, OutputInterface  $output) : int

Description

The method MUST assemble the necessary commands to initiate PHPUnit securely. It SHOULD optionally construct advanced configuration arguments such as caching and coverage.

Parameters
$input : InputInterface

Description

the runtime instruction set from the CLI

$output : OutputInterface

Description

the console feedback relay

Return values
int

Description

the status integer describing the termination code

isJsonOutput()

Protected

Determines whether JSON output was requested.

protected isJsonOutput(InputInterface  $input) : bool

Description

The pretty-json flag SHALL imply JSON output.

Parameters
$input : InputInterface
Return values
bool

isPrettyJsonOutput()

Protected

Determines whether pretty JSON output was requested.

protected isPrettyJsonOutput(InputInterface  $input) : bool
Parameters
$input : InputInterface
Return values
bool

configureCoverageArguments()

Private
private configureCoverageArguments(InputInterface  $input, ProcessBuilderInterface  $processBuilder, bool  $requiresCoverageReport) : ProcessBuilderInterface, string|null}
Parameters
$input : InputInterface

Description

the raw parameter definitions

$processBuilder : ProcessBuilderInterface

Description

the process builder to extend with coverage arguments

$requiresCoverageReport : bool

Description

indicates whether a coverage-php report is required

Return values
ProcessBuilderInterface, string|null}

Description

the extended builder and generated coverage-php report path

failure()

Private

Logs a failed command result and returns the failure exit code.

private failure( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string|null  $file = null][, int|null  $line = null]) : int
Parameters
$message : string

Description

the failure message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

$file : string|null = null

Description

the related file path when known

$line : int|null = null

Description

the related line when known

Return values
int

notice()

Private

Logs an informational command message at notice level.

private notice( string  $message, InputInterface  $input[, array<string, mixed>  $context = []]) : void
Parameters
$message : string

Description

the notice message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

resolveMinimumCoverage()

Private
private resolveMinimumCoverage(InputInterface  $input) : float|null
Parameters
$input : InputInterface

Description

the raw parameter definitions

Return values
float|null

Description

the validated minimum coverage percentage, if configured

resolvePath()

Private

Safely constructs an absolute path tied to a defined capability option.

private resolvePath(InputInterface  $input, string  $option) : string

Description

The method MUST compute absolute properties based on the supplied input parameters. It SHALL strictly return a securely bounded path string.

Parameters
$input : InputInterface

Description

the raw parameter definitions

$option : string

Description

the requested option key to resolve

Return values
string

Description

validated absolute path string

success()

Private

Logs a successful command result and returns the success exit code.

private success( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string  $logLevel = LogLevel::INFO]) : int
Parameters
$message : string

Description

the success message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

$logLevel : string = LogLevel::INFO

Description

the PSR-3 log level used for the successful result

Return values
int

validateMinimumCoverage()

Private
private validateMinimumCoverage( string  $coverageReportPath, float  $minimumCoverage) : array{int, string, array}
Parameters
$coverageReportPath : string

Description

the generated coverage-php report path

$minimumCoverage : float

Description

the required line coverage percentage

Return values
array{int, string, array}

Description

validation result, human message, and structured coverage context