ADR-0004: the Infection adapter
The Infection adapter (infection/infection ~0.35.0, with PHPUnit 12 or 13),
as ADR-0004 decides
it in its fourth decision.
-
Invocation:
vendor/bin/infection --configuration=<generated> --threads=<n>--no-progress --no-interaction --with-uncovered --logger-github=false--coverage=<dir> --skip-initial-tests--test-framework-extra-args=<the project's, the cache directory, and agroup or filter>[--only-covering-test-cases] <files>-
Every PHPUnit the adapter starts, its coverage run, a listing, a run of no test and a control, and each mutant’s run Infection starts through
--test-framework-extra-args, is passed--cache-directory=<project>/.mutation-gate/phpunit-cacheafter the project’s own arguments, whatever its config names, so no run writes a file a content key reads (ADR-0007, ADR-0023). A cache directory the project’s arguments name is dropped, since PHPUnit warns of an option given twice. -
--log-verbosityis left at its default, and nevernone. -
Infection never runs an opening suite of its own. It always reads a coverage directory the adapter wrote in its own job. For a run judged by the whole suite that reuses the planning job’s coverage, the adapter writes the gate’s map that job handed on (ADR-0006) into the layout below. That covers each file’s lines and the tests that ran them, the methods its report says some test ran, with their lines, and a JUnit log with a suite for each test class, holding the file its tokens say declares it and its tests’ times. Otherwise the adapter writes the directory by running PHPUnit under coverage (the Coverage item below). No report another job wrote is read. The adapter reads each mutant’s limit from that directory’s JUnit log, which is what Infection sums, and Infection deletes its own opening run’s log when it finishes.
-
Infection and PHPUnit run on the PHP that runs the gate, with that PHP’s directory first on the
PATH, because Infection starts PHPUnit for each mutant through the script’s#!line. They inherit no variable of another run (INFECTION_*,MUTATION_GATE_*,PEST_MUTATION_*,PARATEST,TEST_TOKEN,UNIQUE_TEST_TOKEN) and no credential (AWS_*,GITHUB_TOKEN,SONAR_TOKEN,ACTIONS_*, and the cloud stores’ of ADR-0028), because the project’s tests and every mutant of its code run in them. -
A project withholds its own credentials from either runner with
runner.withhold, a list of variable names or globs whose*stands for any run of characters, such asDEPLOY_*orCOMPOSER_AUTH. It only adds to what every run withholds, and it only grows: each layer of config adds its own to the earlier layers’, whichever runner a later layer chooses, and a layer may writewithholdalone for zero-config to find the runner. It is not part of a proof’s key (ADR-0007). -
A run stopped at its deadline is cannot judge: Infection writes its logs only when it finishes, so no mutant of such a run has a result. A stopped run is stopped with every process it started.
-
-
Configuration. The adapter writes a config per invocation. It reads the project’s own config where there is one, the first of
infection.json5,infection.json,infection.json5.distandinfection.json.dist, as Infection does.- It keeps only these keys of it:
mutators,bootstrap,phpUnit,initialTestsPhpOptions,testFramework,staticAnalysisTool,staticAnalysisToolOptions,phpStanandmago. The project’stestFrameworkExtraArgsgo on the command line, before the gate’s own narrowing. Every other key either belongs to the gate or could change which mutants Infection makes or how it stops (source,minMsi,minCoveredMsi,maxTimeouts,timeoutsAsEscaped,ignoreMsiWithNoMutations,threads,logsand any key a later release adds), so the gate writes it itself or leaves it out. - Every path is absolute, and
phpUnit.configDiris set, because the generated file lives under.mutation-gate/. - Where the config turns on registered mutators,
bootstrapnames the file of their bridges, which loads the project’s own bootstrap, andmutatorsturns each bridge on (ADR-0021). source.directoriesare the directories of the files the run mutates.logs.jsonandlogs.textpoint into.mutation-gate/infection/logs/, and every other log is off.timeoutistimeouts.most(ADR-0008). Every run is started withMUTATION_GATE_MUTANT_FLOORset totimeouts.seconds, which the linesinfection:patchwrites read, andMUTATION_GATE_RESULTSnaming the file they record silence stops in.
- It keeps only these keys of it:
-
infection:patchgives Infection the gate’s mutant limit. It is@php vendor/bin/mutation-gate infection:patchinpost-install-cmdandpost-update-cmd. The GitHub action runsinfection:patchitself after it installs the project, wherever the effective config runs Infection, so the Composer hook serves every other run. It rewrites six places in Infection and one in its include-interceptor, each marked with a// mutation-gate infection:patch:comment:MutantProcessContainerFactoryallows each mutant the gate’s standard limit (ADR-0008) of Infection’s own time for its covering tests, betweenMUTATION_GATE_MUTANT_FLOORand Infection’stimeout, in place of Infection’s 5 s plus five times that time undertimeout.MutationTestingRunnerskips no mutant for the time its tests take, and makes no mutant of a mutator the gate prunes in a file it prunes it in.TestFrameworkMutantExecutionResultFactoryjudges a run that ran out of its limit timed out, where Infection 0.35.9 judges it skipped once its covering tests’ time reaches that limit.MutantProcessContainerFactoryalso watches each mutant’s run for its silence limit (ADR-0008): the same rule, of its slowest covering test class’s time, as Infection times each test by its whole class, between the same bounds; none where a covering class is untimed.ParallelProcessRunner, as it checks each run’s timeout, stops a run that has printed nothing on its standard output for its silence limit since it last printed. PHPUnit prints its header once it has loaded every test, and a mark as each test ends, so its start is held only to the mutant’s own limit. Each stop is recorded, by the mutant’s file, line, mutator and diff as Infection’s log names them, inlogs/silenced.jsonl, whichMUTATION_GATE_RESULTSnames, and the mutant is timed out at its own limit, with a reason naming the silence limit.IncludeInterceptor, thefile://wrapper infection/include-interceptor serves each mutant through, stats a path as PHP does without it while it is enabled. As it ships, in every release Infection ~0.35.0 allows (0.2.5 and 1.0.0), it reports a path the process cannot read as missing, so a dangling link is no link and a file without read permission is not there, and a test that stats either fails in every mutant’s run whatever the mutant changes. Patched, a link, dangling or not, is stat’d bylstatwhere the caller asks for the link, and any other path that exists bystat. It raises no warning of its own: PHP warns of a failed stat where the caller did not ask for quiet (STREAM_URL_STAT_QUIET), as it does without the wrapper. A release whose lines have moved fails the command, and every patch is checked before any file is written.
The places in Infection read the gate’s floor and pruned list, so Infection run outside the gate keeps its own limit, skip and timeout judgement, prunes no mutant, and stops no run for silence; the interceptor stats as PHP does either way. The command patches only the Infection releases the runner contracts run, listed in
Adapter\Infection\Release, reading the release from Composer’s list of what it installed. Any other release it leaves unpatched, with its own limit, and exits 1. A supported release it cannot patch, because a file’s lines have moved or another version of the gate patched it, it refuses with exit code 2, and says which, aspest:patchdoes. An install fails on either. The action tells them apart by the exit code: it warns of an unpatched release, in the log and the step summary, and goes on, and it fails on a refusal. Each run checks whether the installed Infection and its include-interceptor carry the patch. Where it does not, each mutant keeps Infection’s own limit, the gate triages by that limit, and the run’s report warns of it, naminginfection:patch;doctoradvises it too (infection-unpatched).tmpDiris under.mutation-gate/.- A run is judged by its logs and their counts, never by Infection’s exit code. The logs, the generated config and the coverage reports an earlier run left are removed before a run, and a file that cannot be removed is cannot judge.
-
Held paths (ADR-0005) always take coverage from their own opening run, never from a whole-suite map. The adapter runs PHPUnit under coverage narrowed to the holding tests, and Infection reads that run’s directory. The narrowing also goes through
--test-framework-extra-args.- A group,
--group holds:<path>, narrows the opening run and every mutant run. PHPUnit, started by the adapter, takes each option and its value apart, since its reading of--name=valueends the value at its next=; among the extra arguments Infection passes on, the group and the filter keep--group=and--filter=, by which Infection finds them. #[Holds]becomes a--filternaming the holding tests. It narrows the opening run, and each mutant run then executes only tests that run recorded. The adapter adds--only-covering-test-cases, so a mutant runs the holding test methods rather than their whole classes.- A contract test proves both.
- A group,
-
Results. The adapter reads
logs.json, and the skipped mutants fromlogs.text. The logs must add up, or the run is cannot judge:statscountWhere the mutants are Gate status killedCountkilledkilled killedByStaticAnalysisCountkilledByStaticAnalysiskilled by static analysis escapedCountescapedsurvived errorCounterrorederrored syntaxErrorCountsyntaxErrorserrored timeOutCounttimeoutedtimed out notCoveredCountuncovereduncovered skippedCountSkipped mutants:inlogs.textskipped ignoredCountignoredignored by a native marker when ignores.native: allow; otherwise cannot judge, because the run refuses native markers before it starts (ADR-0008)Each count must equal the number of its mutants, and
totalMutantsCountmust equal the sum of the counts.A mutant under
killedcarries the tests that killed it (ADR-0014): the ones PHPUnit’s output, the entry’sprocessOutput, lists underThere was 1 failure:orThere were 2 errors:. Each is named as the coverage map names it,<class>::<method>with#<data set>for a data set’s test. A class whosesetUpBeforeClassfailed or errored is listed by its name alone, and stands for each test of it the coverage map knows, as a class any list below names alone does. Infection’s mutant runs stop at the first defect, so that is the first killer. Where no test failed or met an error, the run failed on an issue: Infection addsfailOnRiskyandfailOnWarningto the project’s PHPUnit config where it sets neither, and PHPUnit fails a run on its own warnings of a test unlessfailOnPhpunitWarningsays not. The mutant then carries the tests whose issues the config fails the run on, as the output lists them: each test underThere was 1 risky test:and1 test triggered 1 PHPUnit warning:, each test a warning under1 test triggered 2 PHP warnings:or… 1 warning:lists afterTriggered by:, and, for such a warning raised in a test itself, which PHPUnit prints by its file and line alone, each data set the coverage map knows of the test method that line is in. Its unmutated control runs on a config that fails as the mutant’s run did, with the same two attributes added where the project’s sets neither, so a test whose issue it raises unmutated too never counts as its killer. A mutant killed by static analysis, an error or a timeout, or with no such list, carries none, and one killed by static analysis carries no rejection either, since the log names no finding. -
Coverage comes from
vendor/bin/phpunit --coverage-xml=<dir>/coverage-xml --log-junit=<dir>/junit.xml, orphpUnit.customPath, withinitialTestsPhpOptionsas PHP options, then the pcov settings Pest’s coverage run takes, which win over them, the project’stestFrameworkExtraArgsand, for a held path, its group or filter. That is the layout--coverageexpects, and the gate reads its per-linecovered byentries as its own map, so one run serves both. The map also keeps the methods Infection finds a signature mutant’s tests by: each method of the report’s classes or, where they have none, of its traits, with the start and end lines the report gives it, less each whose coverage Infection reads as none (under one percent). Groups come fromvendor/bin/phpunit --list-groups. -
Limits. A timed-out or skipped mutant’s limit is
min(5 s + 5 × T, timeout), whereTis the sum of the JUnit times of the test classes covering its first line, each counted once, as Infection computes it. -
Native markers (ADR-0008) are
@infection-ignore-allin a comment of the files asked for, and each value ofignoreorignoreSourceCodeByRegexundermutatorsin the project’s config: under a mutator, a profile,global-ignoreorglobal-ignoreSourceCodeByRegex. -
Scope. The adapter refuses a
testFrameworkother thanphpunit, and aphpUnit.customPaththat points at Pest. A Pest project uses the Pest adapter. -
Narrowing to one mutator. A retry (ADR-0008) or a reproduce runs the mutant’s file with a generated config whose
mutatorsblock keeps only that mutator, with the project’s settings for it.--mutatorsis never used, because it drops those settings and the mutant could change. The mutant is matched back by the gate’s id.