JoliNotifExecutionFinishedSubscriber

Class
implements ExecutionFinishedSubscriber
Read only: Yes Final: Yes

Sends a desktop notification when the PHPUnit execution finishes.

Description

This subscriber MUST summarize the current PHPUnit run using the counters collected by the shared event tracer and SHALL dispatch a concise desktop notification through the configured notifier implementation.

The generated notification MUST preserve the effective behavior currently expected by the application:

  • successful runs SHALL report only the total number of executed tests, followed by expanded telemetry details;
  • unsuccessful runs SHALL report the number of passed tests together with the relevant failure and error counters, followed by expanded telemetry details.

When process forking support is available, notification delivery SHOULD be delegated to a child process so the main PHPUnit process MAY continue shutting down without waiting for the desktop notification transport to complete.

Tags
codeCoverageIgnore

Table of Contents

Interfaces

Properties

 : NotifierInterface

Methods

__construct()

Creates a new execution-finished subscriber instance.

 : mixed
notify()

Handles the PHPUnit execution finished event.

 : void
getBody()

Builds the main notification body for the current execution result.

 : string
getFailedBody()

Builds the notification body for a test run containing failures or errors.

 : string
getPassedTests()

Calculates the number of tests that completed successfully.

 : int
getSuccessBody()

Builds the notification body for a fully successful test run.

 : string
getTelemetryBody()

Builds the telemetry block appended to the notification body.

 : string
getTitle()

Builds the notification title for the current execution result.

 : string
hasIssues()

Determines whether the current test run contains at least one failure or error.

 : bool
Properties
Methods

__construct()

Public

Creates a new execution-finished subscriber instance.

public __construct(EventTracer  $tracer[, NotifierInterface  $notifier = new DefaultNotifier()]) : mixed

Description

The provided tracer MUST contain the event history collected during the current PHPUnit run so this subscriber can derive an accurate summary. When no notifier is explicitly provided, the default JoliNotif notifier SHALL be used.

Parameters
$tracer : EventTracer

Description

the event tracer used to inspect recorded PHPUnit events and derive notification data

$notifier : NotifierInterface = new DefaultNotifier()

Description

the notifier responsible for dispatching the desktop notification

notify()

Public

Handles the PHPUnit execution finished event.

public notify(ExecutionFinished  $event) : void

Description

This method MUST build the final notification payload using the computed title, execution summary, and telemetry details. When process forking is available, the parent process SHALL return immediately after a successful fork, and the child process SHALL send the notification and terminate explicitly. When forking support is not available, or the fork attempt fails, the notification MUST still be delivered synchronously so functional behavior remains unchanged.

Parameters
$event : ExecutionFinished

Description

the emitted PHPUnit execution finished event

getBody()

Private

Builds the main notification body for the current execution result.

private getBody() : string

Description

Successful executions MUST produce a minimal body containing only the total number of executed tests. Executions with failures or errors SHALL produce a body containing the number of passed tests together with the relevant failure and error counters.

Return values
string

Description

the formatted notification body

getFailedBody()

Private

Builds the notification body for a test run containing failures or errors.

private getFailedBody() : string

Description

The failed body MUST include the total number of passed tests and SHALL include failure and error counters only when those counters are greater than zero.

Return values
string

Description

the formatted failure body

getPassedTests()

Private

Calculates the number of tests that completed successfully.

private getPassedTests() : int

Description

The returned value MUST NEVER be negative, even if the collected event counters become inconsistent for any reason.

Return values
int

Description

the number of successfully completed tests

getSuccessBody()

Private

Builds the notification body for a fully successful test run.

private getSuccessBody() : string

Description

The success body SHOULD remain intentionally brief because additional diagnostic detail is unnecessary when all tests pass.

Return values
string

Description

the formatted success body

getTelemetryBody()

Private

Builds the telemetry block appended to the notification body.

private getTelemetryBody(ExecutionFinished  $event) : string

Description

PHPUnit telemetry MUST be expanded into explicit, human-readable metrics instead of being displayed as a compact raw string. This method SHALL expose the most relevant execution data in a readable multi-line block, including runtime, memory consumption, suite progression, prepared test count, and the overall assertion status.

Parameters
$event : ExecutionFinished

Description

the PHPUnit execution finished event

Return values
string

Description

the formatted telemetry block, including its leading line breaks

getTitle()

Private

Builds the notification title for the current execution result.

private getTitle() : string

Description

Successful executions MUST produce a success-oriented title. Executions containing at least one failure or error SHALL produce a failure-oriented title.

Return values
string

Description

the formatted notification title

hasIssues()

Private

Determines whether the current test run contains at least one failure or error.

private hasIssues() : bool
Return values
bool

Description

true when the execution contains failures or errors; otherwise false