Search by

adachsoft / phpunit-runner-lib

Arkadiusz Adach

Library for running PHPUnit via CLI and parsing results into structured DTOs.

Package info

gitlab.com/a.adach/phpunit-runner-lib

Issues

pkg:composer/adachsoft/phpunit-runner-lib

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-09-18 05:51 UTC

This package is not auto-updated.

Last update: 2026-09-19 02:26:03 UTC


README

A PHP library for running PHPUnit through the command line and converting test output into structured results.

Features

  • Execute PHPUnit with a configurable working directory and binary path.
  • Run a complete test suite or target a specific path.
  • Support PHPUnit configuration files, filters, groups, coverage, and timeouts.
  • Capture standard output, error output, exit codes, and a human-readable summary.
  • Parse failures, errors, warnings, notices, and deprecations into file issues.
  • Work safely with relative test paths.

Requirements

  • PHP 8.3 or newer.
  • PHPUnit available in the configured project.

Installation

composer require adachsoft/phpunit-runner-lib

Basic usage

<?php

declare(strict_types=1);

use AdachSoft\CommandExecutorLib\SimpleCommandExecutor;
use AdachSoft\PhpUnitRunnerLib\Config\PhpUnitRunnerConfigDto;
use AdachSoft\PhpUnitRunnerLib\Dto\RunPhpUnitRequestDto;
use AdachSoft\PhpUnitRunnerLib\Parser\PhpUnitOutputParser;
use AdachSoft\PhpUnitRunnerLib\PhpUnitRunner;

$projectRoot = dirname(__DIR__);

$runner = new PhpUnitRunner(
    new PhpUnitRunnerConfigDto(
        basePath: $projectRoot,
        phpUnitPath: 'vendor/bin/phpunit',
        defaultTimeout: 60,
    ),
    new SimpleCommandExecutor(),
    new PhpUnitOutputParser(),
);

$result = $runner->run(
    new RunPhpUnitRequestDto(
        path: 'tests',
        coverage: false,
    ),
);

if (!$result->success) {
    foreach ($result->fileIssues->all() as $issue) {
        printf("%s:%s [%s] %s\n", $issue->file, $issue->line ?? '-', $issue->type, $issue->message);
    }
}

printf("Exit code: %d\n%s\n", $result->exitCode, $result->summary);

Configuration

PhpUnitRunnerConfigDto accepts the project base path, the PHPUnit binary path, an optional default timeout, and flags controlling PHPUnit notices, warnings, and deprecations.

RunPhpUnitRequestDto can target a path and can provide a PHPUnit XML configuration, filter, group, coverage flag, and per-run timeout. The runner returns a RunPhpUnitResultDto containing the raw output, exit code, summary, success state, and a FileIssueCollection.

See the examples for focused usage patterns.

License

MIT