Index

TestRunner

MMO\core · 1 symbol · generated 30 Sep 2026

class

TestRunner

TestRunner.php:40

Runs a package's phpunit suite and reports the result as data.

class MMO\core\TestRunner extends MMO\core\classes\aModule
Namespace
MMO\core
Extends
aModule
Any installed package is runnable: a package declares where its phpunit configuration is with the `tests` key of its `mmo.json` ([`PackageManifest::$tests`](https://mmoframework.fr/documentation/mmo.core/php/helpers/PackageManifest.md#packagemanifest-tests), `phpunit.xml` by default), and everything else follows from that one file -- which suites exist, which bootstrap to load, what to include. Nothing about a particular library is hard-coded here. ### What it actually runs phpunit itself, as a subprocess, with its machine-readable log turned on: ``` phpunit -c <the package's phpunit.xml> --log-junit <a temp file> --cache-directory <a temp dir> --do-not-cache-result --no-coverage --colors=never [--testsuite <name>] ``` The cache directory and the log are forced into [`$cacheFolder`](https://mmoframework.fr/documentation/mmo.core/php/TestRunner.md#testrunner-cachefolder) rather than left to the configuration: a suite run from the web server would otherwise try to write `.phpunit.cache` into the package folder, which is normally not writable by that user -- and a test run that fails for that reason looks exactly like a test run that failed. The JUnit log is the result; the console output is kept as well, because it is the only thing left to read when phpunit fails *before* running anything (a broken configuration, a missing bootstrap, no suite at all). ### It is a development tool Running a test suite executes the package's own code, with whatever side effects its tests have. [`$enabled`](https://mmoframework.fr/documentation/mmo.core/php/TestRunner.md#testrunner-enabled) is therefore off outside dev mode, and [`TestController`](https://mmoframework.fr/documentation/mmo.core/php/controllers/TestController.md#testcontroller) refuses every request when it is.
$result = \MMO\core\TestRunner::Shared()->run('mmo.core'); echo $result['tests'], ' tests, ', $result['failures'], " failures\n";

Index

binaries
binary
cacheFolder
enabled
maxOutputBytes
timeout
buildCommand($config, $log, $cache, $suite)Build the phpunit command line, every token escaped.
collectProblems($suite, $suiteName, $problems)Walk a suite's tree and collect every test case that did not pass.
DefaultConfig() static
emptyResult()
getBinary()
getLibraries()Every installed package that ships a test suite.
getSuites($config)The test suites a phpunit configuration declares, so one can be run on its own.
parse($xml)Turn phpunit's JUnit log into the result this module reports.
run($library, $suite)Run one package's test suite.
runAll()Run every package that ships a test suite.

Properties6

binaries

array $binaries = ['{root}/vendor/bin/phpunit', '{root}/../vendor/bin/phpunit']
Type
array

cacheFolder

?string $cacheFolder = null
Type
null | string
The default is null on purpose: a shared folder under `{tmp}` is created by whoever runs first and is then owned by them, so the next run -- from the web server, from a cron, from another developer -- finds a directory it cannot write into, and every suite fails for a reason that has nothing to do with the tests. Set it only when the cache is worth keeping and the permissions are under control.

enabled

bool $enabled = true
Type
bool

maxOutputBytes

int $maxOutputBytes = 262144
Type
int

timeout

float $timeout = 300.0
Type
float

Methods10

buildCommand($config, $log, $cache, $suite)

TestRunner.php:253

Build the phpunit command line, every token escaped.

protected function buildCommand(string $config, string $log, string $cache, ?string $suite = null): string
$configstringthe package's phpunit.xml
$logstringwhere the JUnit log is written
$cachestringthe cache directory phpunit is forced to use
$suite = nullnull | string
returnsstring

collectProblems($suite, $suiteName, $problems)

TestRunner.php:328

Walk a suite's tree and collect every test case that did not pass.

protected function collectProblems(SimpleXMLElement $suite, string $suiteName, array &$problems): void
$suiteSimpleXMLElement
$suiteNamestringthe top-level suite everything below belongs to
$problemsarray
returnsvoid

emptyResult()

TestRunner.php:350
protected function emptyResult(): array
returnsarraya result with nothing in it -- what a run that never got to execute a test reports.

getLibraries()

TestRunner.php:80

Every installed package that ships a test suite.

function getLibraries(): array
returnsarraystring, version: string, namespace: string, config: string, folder: string, suites: array<string>}> keyed by package name, in natural order
array_keys(\MMO\core\TestRunner::Shared()->getLibraries());// ['mmo.admin', 'mmo.client', ...]

getSuites($config)

TestRunner.php:111

The test suites a phpunit configuration declares, so one can be run on its own.

function getSuites(string $config): array
$configstringthe phpunit.xml filename
returnsarraythe suite names, empty when the file declares none (or cannot be read)

parse($xml)

TestRunner.php:283

Turn phpunit's JUnit log into the result this module reports.

function parse(string $xml): arrayJUnit nests a `<testsuite>` per suite, per class and per data provider, which is more structure than a report needs: this keeps the **top level** suites as the summary rows, and flattens every failing or erroring `<testcase>` into one flat list of problems -- what a reader wants is "what broke", not a tree.
$xmlstringthe log's content
returnsarray

run($library, $suite)

TestRunner.php:158

Run one package's test suite.

function run(string $library, ?string $suite = null): array
$librarystringthe package name (mmo.core)
$suite = nullnull | stringone suite of its configuration, null for all of them
returnsarray{library, suite, config, command, ok, timedOut, exitCode, duration, tests, assertions, errors, failures, skipped, suites: [{name, tests, ...}], problems: [{suite, test, type, kind, message, file, line}], output}
throwswhen the package is not installed, or ships no test suite
throwswhen running tests is disabled

runAll()

TestRunner.php:228

Run every package that ships a test suite.

function runAll(): array
returnsarray{libraries: [name => result], tests, assertions, failures, errors, skipped, duration, ok}
$all = \MMO\core\TestRunner::Shared()->runAll(); echo $all['ok']? 'green' : 'red';
Inherited members (47)
ConstantsDeclared byDescription
ALERTiLogLevelAlert: Action must be taken immediately.
ALLiLogLevelMask for all
ALL_PLUSiLogLeveldebug everything
BACKTRACEiLogLevel
CRITICALiLogLevelCritical: Critical conditions.
DEBUGiLogLevelDebug: Detailed debug information.
DEEPiLogLeveldebug everything with arguments
EMERGENCYiLogLevelEmergency: System is unusable.
ERRORiLogLevelError: Runtime errors that do not require immediate action but should typically be logged and monitored.
ERROR_PLUSiLogLevelMask for all error
FATALiLogLevelMask for all fatal error
INFOiLogLevelInfo: Interesting events.
INFO_PLUSiLogLevelMask for all errors/warning/notices/info
MEMORYiLogLevelinclude backtrace object
NOTICEiLogLevelNotice: Normal but significant events.
NOTICE_PLUSiLogLevelMask for all errors/warning/notices/info
TRACEiLogLevelinclude backtrace as origins
WARNINGiLogLevelWarning: Exceptional occurrences that are not errors.
WARNING_PLUSiLogLevelMask for all errors and warnings
PropertiesDeclared byDescription
verbosityaModule
MethodsDeclared byDescription
alert($message, $context)aModuleAction must be taken immediately.
backtraces($message, $context)aModuleForce-log a message at INFO level together with a full stack trace/memory snapshot (iLogLevel::BACKTRACE), bypassing the verbosity mask entirely (any non-zero verbosity is enough to trigger it).
Configure($config)aModuleMerge $config into this module's configuration in the shared Configuration.
critical($message, $context)aModuleCritical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask.
debug($message, $context)aModuleDetailed debug information.
debugName()aModuleHuman-readable identifier used as the default {origin} in this instance's log messages.
emergency($message, $context)aModuleSystem is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.
error($message, $context)aModuleRuntime errors that do not require immediate action but should typically be logged and monitored.
getVerbosity()aModule
info($message, $context)aModuleInteresting events. No-op if INFO is currently filtered out by the verbosity mask.
Instantiate($config)aModule(Re)create the shared instance immediately, configured with $config merged into the class's existing config.
IsShared()aModule
log($level, $message, $context)aModuleLogs with an arbitrary level.
notice($message, $context)aModuleNormal but significant events.
offsetExists($key)aModule\ArrayAccess::offsetExists -- tells whether $key is a declared property at all, regardless of whether it is currently readable/writable through array access.
offsetGet($key)aModule\ArrayAccess::offsetGet -- reads a property directly, unless it has a #[Serialize(serialize: 'methodName')] attribute, in which case that zero-argument method is called instead (e.g.
offsetSet($key, $value)aModule\ArrayAccess::offsetSet -- sets a property directly, unless it has a #[Serialize(unserialize: 'methodName')] attribute, in which case that method is called with $value instead (e.g.
offsetUnset($key)aModule\ArrayAccess::offsetUnset -- equivalent to $module[$key] = null.
serialize($path, $serializer)aModule\MMO\core\interfaces\iSerializable::serialize -- exports every property (via
setVerbosity($verb)aModuleSet the current verbosity mask, replacing whatever it was before.
Shared()aModuleGet the shared instance, creating (and configuring) it on first call.
testVerbosity($level)aModuleTest whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.
traitUnshare($serialize)aModuleRemove the shared instance, so the next Shared() call creates a fresh one.
unserialize($data, $path, $instances)aModule\MMO\core\interfaces\iSerializable::unserialize -- merges $data onto DefaultConfig, runs it through the (possibly overridden) constructor, then applies each resulting value to its property (via
Unshare($serialize)aModuleLike tSingleton::Unshare, but also disconnects this module's instance from every event it was listening to (via Event::DisconnectListeners) before dropping it.
warning($message, $context)aModuleExceptional occurrences that are not errors.
__construct($config)aModuleprotected constructor, so it is not possible to do new Module(...) called by the serialization process just before being injected with data.