Fixtures
Every rule has its own fixtures in internal/inspection/rules/<lowercase-ID>/testdata/. They are the CI gate (make fixtures) and, with the rule packages' tests, must cover 100% of the rule's statements (make coverage). This page is the reference for their format.
Files
internal/inspection/rules/onetimeusevariables/testdata/
├── basic.php # findings, marked up
├── basic.fixed.php # expected source after applying the fixes
├── false-positives.php # code that must not be reported
├── options.php # same rule with non-default options…
├── options.json # …set by this sidecar
└── old.php / old.json # behavior on an older PHP versionName fixtures by what they hold:
basic.phpholds the main findings andfalse-positives.phpthe code that must not be reported. Do not usepositive.php,negative.phporvalid.php.When some cases that must not be reported cannot share
false-positives.php, because they need other settings or their own global state, namespace or imports, put them infalse-positives-<topic>.php.Any other fixture gets a short descriptive name: the option, PHP version or construct it covers (
options.php,old.php,guards.php).<name>.php: a fixture. Every expected finding is marked up (see below); anything not marked must not be reported.<name>.fixed.php(optional): the expected result of applying, in one pass, the quick-fixes of<name>.php, markup removed. Whitespace differences are ignored. Without one, applying the fixes must leave the fixture unchanged: a quick-fix is always shown by a.fixed.php.<name>.json(optional): settings for that fixture. Leave out keys that restate a default ("options": {}, the defaultphpversion), and the file when nothing is left.*.inc: extra project files whose symbols are indexed next to a fixture (seecompanions); they are not fixtures themselves.
Every rule needs findings, the false positives it must avoid and, when it has a fix, its expected result: basic.php, false-positives.php and basic.fixed.php, plus one fixture per option or PHP version that changes the behavior. Start from the spec's examples. Cover parser-recovery guards with broken PHP in broken*.php.
Own fixtures are parsed with the newest supported syntax, in permissive mode and with short open tags; the rule itself sees the fixture's target PHP version.
Markup
Wrap the highlighted code in a tag named after the severity, with the exact message in descr:
<?php
function total($a) {
<warning descr="Variable $total is used only once; inline its value.">$total</warning> = $a + 1;
return $total;
}- Tags:
error,warning,weak_warning(reported asinfo) andinfo. - The range must match the finding exactly, and the message is compared exactly.
- Tags may nest. A
<caret>marker is accepted and ignored. descris HTML-unescaped: write"for"and<for<.
Sidecar settings
{
"php": "7.4",
"comparisonStyle": "yoda",
"options": { "ALLOW_LONG_STATEMENTS": true, "configuration": ["\\App\\dump"] },
"companions": ["Base.inc"]
}| Key | Meaning |
|---|---|
php | Target PHP version for this fixture (default 8.4). |
comparisonStyle | regular or yoda. |
options | Rule options (bool, number, string or list); a Rule.OPTION key sets an option of a with rule. |
calls | Rarely needed: list options given as registration calls. |
companions | Extra project files (relative to the rule directory) to index. |
with | Other rules enabled in the same run; their findings are marked up too (for rules that leave findings to one another). |
vendorDir | The project's vendor directory (Composer's config.vendor-dir), relative to the testdata directory; default vendor. Classes of companions under it belong to dependencies. |
assertions | true trusts assert() calls as guards, as the flow.assertions setting does. |
extensions | PHP extensions the project requires (ext-… in composer.json), named as the stubs name them (sodium, zend-opcache). |
completeWorld | true indexes the fixture and its companions as everything the project can load (see the index world), so a name they do not declare exists nowhere. |
Rules on other files
Rules that read a manifest instead of PHP (such as SecurityAdvisories on composer.json) use one directory per case: <case>/composer.json, with optional composer.fixed.json and composer.config.json.
Running
make fixtures RULE=OneTimeUseVariables
make coverage # lists uncovered blocks of internal/inspection/rulesmake fixtures runs every rule's fixtures in one test of internal/testing/conformance; rule packages do not need their own fixture runner. A few fixtures listed in that package's fixRoundTrips are held to a stricter fix check: the fixed output must match byte for byte, and the rule must report nothing on it.
Upstream conformance
make conformance reads fixtures from the local upstream checkout at test time. Cases without an explicit target run at PHP 5.6. The harness parses with the latest supported syntax in permissive mode, while inspections use the case's PHP target. Companion files configured by the same test are indexed together. IDE syntax-error markers are excluded from inspection expectations.
Fix comparison applies the first analysis's fixes in one pass, resolving edit conflicts together, and collapses whitespace for comparison. This checks single-pass editor behavior separately from the CLI's iterative fix loop. Intentional differences belong in the rule specification's Divergences section and internal/testing/conformance/testdata/ea-divergences.json. See the clean-room process for restrictions on failure output.
