TestsCommand

Class
extends Command
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 : 'reports:tests'
$description : 'Runs PHPUnit tests.'
$aliases : ['phpunit', 'tests']

Table of Contents

Constants

 = 'fast-forward/dev-tools'
 = 'phpunit.xml'
 = 'FAST_FORWARD_MIN_COVERAGE'
 = 'Running PHPUnit Tests'

Properties

Methods

 : mixed
addCacheDirOption()

Adds the standard cache directory option to the current command.

 : static
addCacheOption()

Adds the standard cache control option to the current command.

 : static
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
isCacheEnabled()

Resolves whether cache writes SHOULD be enabled for the current invocation.

 : bool
isJsonOutput()

Determines whether JSON output was requested.

 : bool
isPrettyJsonOutput()

Determines whether pretty JSON output was requested.

 : bool
resolveCacheArgument()

Returns the explicit cache flag that SHOULD be forwarded to nested commands.

 : string|null
resolveCacheDirArgument()

Resolves a nested cache directory for a child command.

 : string|null
 : ProcessBuilderInterface, string|null}
decodeStructuredProcessOutput()

Attempts to decode structured PHPUnit output while preserving any non-JSON prelude that was emitted before the final reporter payload.

 : array{array|null, string|null}
failure()

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

 : int
forceAgentReporter()

Forces the PHPUnit subprocess to expose the agent reporter payload.

 : void
hasExplicitCacheDirArgument()

Determines whether the current invocation explicitly passed `--cache-dir`.

 : bool
isDefaultTestsPath()

Detects whether a tests path option still points at the default project tests directory.

 : bool
isImplicitJsonOutputEnabled()

Determines whether structured JSON output SHOULD be enabled implicitly.

 : bool
isNoCacheRequested()

Determines whether cache writes were explicitly disabled for the current invocation.

 : bool
isOptionEnabled()

Determines whether a boolean input option was enabled.

 : bool
log()

Logs a non-terminal command message unless structured JSON output is active.

 : void
normalizeProjectRelativePath()

Normalizes a project-relative path for resilient default-option comparisons.

 : string
resolveBootstrapPath()

Creates the bootstrap shim path passed to PHPUnit.

 : string
resolveMinimumCoverageFromEnvironment()

Resolves minimum-coverage value from injected environment abstraction.

 : string|false|null
resolvePath()

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

 : string
resolveProcessResultContext()

Builds structured context for the executed PHPUnit process.

 : array<string, array<string, mixed>|OutputInterface>
resolveStructuredProcessResultPayload()

Builds the structured payload that will be emitted for agent-oriented runs.

 : array<string, mixed>
success()

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

 : int
 : array{int, string, array}
withStructuredCoverageValidationContext()

Appends minimum-coverage validation data to the structured PHPUnit output payload.

 : array<string, mixed>
Constants

Constants

AGENT_ENVIRONMENT_VALUE

Public
public string AGENT_ENVIRONMENT_VALUE = 'fast-forward/dev-tools'

AGENT_ENVIRONMENT_VARIABLE

Public
public string AGENT_ENVIRONMENT_VARIABLE = 'AI_AGENT'

CONFIG

Public
public string CONFIG = 'phpunit.xml'

Description

identifies the local configuration file for PHPUnit processes

ENV_MINIMUM_COVERAGE

Public
public string ENV_MINIMUM_COVERAGE = 'FAST_FORWARD_MIN_COVERAGE'

PROCESS_LABEL

Private
private string PROCESS_LABEL = 'Running PHPUnit Tests'
Properties

$fileLocator

Private Read-only
private FileLocatorInterface $fileLocator
Methods

__construct()

Public
public __construct(CoverageSummaryLoaderInterface  $coverageSummaryLoader, ComposerJsonInterface  $composer, FilesystemInterface  $filesystem, BootstrapShimGenerator  $bootstrapShimGenerator, FileLocatorInterface  $fileLocator, ProcessBuilderInterface  $processBuilder, ProcessQueueInterface  $processQueue, ProjectCapabilitiesResolverInterface  $projectCapabilitiesResolver, EnvironmentInterface  $environment) : 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

$bootstrapShimGenerator : BootstrapShimGenerator

Description

the generator used to build the PHPUnit bootstrap shim

$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

$projectCapabilitiesResolver : ProjectCapabilitiesResolverInterface

Description

the project capability resolver

$environment : EnvironmentInterface

Description

the environment resolver for CLI-scoped flags

addCacheDirOption()

Protected

Adds the standard cache directory option to the current command.

protected addCacheDirOption( string  $description, string  $default) : static
Parameters
$description : string

Description

the cache directory option description

$default : string

Description

the command-specific default cache directory

Return values
static

addCacheOption()

Protected

Adds the standard cache control option to the current command.

protected addCacheOption( string  $description) : static
Parameters
$description : string

Description

the cache option description

Return values
static

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

isCacheEnabled()

Protected

Resolves whether cache writes SHOULD be enabled for the current invocation.

protected isCacheEnabled(InputInterface  $input[, bool  $default = true]) : bool
Parameters
$input : InputInterface

Description

the current command input

$default : bool = true

Description

the command-specific default cache behavior when the option is omitted

Return values
bool

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

resolveCacheArgument()

Protected

Returns the explicit cache flag that SHOULD be forwarded to nested commands.

protected resolveCacheArgument(InputInterface  $input) : string|null
Parameters
$input : InputInterface

Description

the current command input

Return values
string|null

resolveCacheDirArgument()

Protected

Resolves a nested cache directory for a child command.

protected resolveCacheDirArgument(InputInterface  $input[, string  $path = '']) : string|null
Parameters
$input : InputInterface

Description

the current command input

$path : string = ''

Description

the child cache path relative to the current command cache root

Return values
string|null

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

decodeStructuredProcessOutput()

Private

Attempts to decode structured PHPUnit output while preserving any non-JSON prelude that was emitted before the final reporter payload.

private decodeStructuredProcessOutput( string  $rawOutput) : array{array|null, string|null}
Parameters
$rawOutput : string

Description

the captured subprocess output

Return values
array{array|null, string|null}

Description

decoded payload and preserved supplemental output

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

forceAgentReporter()

Private

Forces the PHPUnit subprocess to expose the agent reporter payload.

private forceAgentReporter(Process  $process) : void
Parameters
$process : Process

Description

the configured PHPUnit process

hasExplicitCacheDirArgument()

Private

Determines whether the current invocation explicitly passed `--cache-dir`.

private hasExplicitCacheDirArgument(InputInterface  $input) : bool
Parameters
$input : InputInterface

Description

the current command input

Return values
bool

isDefaultTestsPath()

Private

Detects whether a tests path option still points at the default project tests directory.

private isDefaultTestsPath( string  $testsPath) : bool
Parameters
$testsPath : string

Description

the tests path argument received from the CLI

Return values
bool

Description

true when the provided path is equivalent to the default tests directory

isImplicitJsonOutputEnabled()

Private

Determines whether structured JSON output SHOULD be enabled implicitly.

private isImplicitJsonOutputEnabled() : bool

Description

Commands MAY opt into runtime-environment-aware behavior by exposing a $runtimeEnvironment property. Commands that do not expose it SHALL fall back to the shared runtime-environment service from the DevTools container.

Return values
bool

isNoCacheRequested()

Private

Determines whether cache writes were explicitly disabled for the current invocation.

private isNoCacheRequested(InputInterface  $input) : bool

Description

The Composer application already provides a global --no-cache flag, so commands SHALL reuse that switch instead of redefining a local negated variant.

Parameters
$input : InputInterface

Description

the current command input

Return values
bool

isOptionEnabled()

Private

Determines whether a boolean input option was enabled.

private isOptionEnabled(InputInterface  $input, string  $option) : bool
Parameters
$input : InputInterface
$option : string
Return values
bool

log()

Private

Logs a non-terminal command message unless structured JSON output is active.

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

Description

the progress 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 message

normalizeProjectRelativePath()

Private

Normalizes a project-relative path for resilient default-option comparisons.

private normalizeProjectRelativePath( string  $path) : string
Parameters
$path : string

Description

the project-relative path to normalize

Return values
string

Description

the normalized project-relative path

resolveBootstrapPath()

Private

Creates the bootstrap shim path passed to PHPUnit.

private resolveBootstrapPath(InputInterface  $input) : string
Parameters
$input : InputInterface

Description

the raw parameter definitions

Return values
string

Description

the generated bootstrap shim path

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

resolveMinimumCoverageFromEnvironment()

Private

Resolves minimum-coverage value from injected environment abstraction.

private resolveMinimumCoverageFromEnvironment() : string|false|null
Return values
string|false|null

Description

the configured coverage threshold or a falsey fallback

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

resolveProcessResultContext()

Private

Builds structured context for the executed PHPUnit process.

private resolveProcessResultContext(OutputInterface  $processOutput, int  $exitCode, bool  $structuredOutput) : array<string, array<string, mixed>|OutputInterface>
Parameters
$processOutput : OutputInterface

Description

the output sink used while the process ran

$exitCode : int

Description

the exit code returned by the process queue

$structuredOutput : bool

Description

whether the command captured subprocess output for structured logging

Return values
array<string, array<string, mixed>|OutputInterface>

resolveStructuredProcessResultPayload()

Private

Builds the structured payload that will be emitted for agent-oriented runs.

private resolveStructuredProcessResultPayload(OutputInterface  $processOutput, int  $exitCode) : array<string, mixed>
Parameters
$processOutput : OutputInterface

Description

the output sink used while the process ran

$exitCode : int

Description

the exit code returned by the process queue

Return values
array<string, mixed>

Description

the structured process payload

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

withStructuredCoverageValidationContext()

Private

Appends minimum-coverage validation data to the structured PHPUnit output payload.

private withStructuredCoverageValidationContext( array<string, mixed>  $context, array<string, float|int|string|null>  $coverageContext, float  $minimumCoverage, int  $validationResult, string  $message) : array<string, mixed>
Parameters
$context : array<string, mixed>

Description

the command result context

$coverageContext : array<string, float|int|string|null>

Description

structured coverage metrics

$minimumCoverage : float

Description

the required coverage percentage

$validationResult : int

Description

the post-PHPUnit validation status

$message : string

Description

the validation message

Return values
array<string, mixed>

Description

the enriched structured command context