Skip to content

Commit e7e2e3c

Browse files
rpgmemclaude
andauthored
style(tests): reindent tests/ to tabs, and enforce it (#1005)
* style(tests): reindent to tabs, and enforce it tests/ was split 249 files on four spaces against 170 on tabs, with nothing enforcing either — phpcs.xml.dist excludes the directory. A reformat alone would have drifted back within a week, so the gate is the point: phpcs-tests. xml.dist carries exactly two sniffs (DisallowSpaceIndent, ScopeIndent) and runs over the whole directory in the PHPCS workflow, not only over changed files. The exclusion in the main ruleset stays. WordPress-Docs would demand a file, class and method docblock in all 420 files, which is a project rather than a cleanup, and widening this second ruleset is how it stops being cheap. The conversion was mechanical and verified rather than eyeballed: leading spaces to tabs at four columns, then expanded back and compared byte for byte against the original. Every one of the 249 files round-tripped exactly, which is what proves only leading indentation moved. tests/ contains no heredoc or nowdoc, so the usual hazard of reindenting inside a string literal does not arise. One file (UserProfileRestControllerTest) held 512 space-indented lines and a single stray tab — that line was normalised to spaces first so the same round-trip check applied to it too. The diff is 95,675 insertions against 95,675 deletions, and every file parses. The five dependency-free guards pass, and the vacuous-test baseline regenerates identical, so the reindent did not shift what AssertionCoverageTest reads. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NuKPjGyg2b8t48Vr9dB7sm * docs(changelog): note the tests/ reindent + indentation gate (#1005) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c5b89aa commit e7e2e3c

254 files changed

Lines changed: 95734 additions & 95675 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/phpcs.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ jobs:
4545
if: steps.changed.outputs.files != ''
4646
run: |
4747
vendor/bin/phpcs -q --report=checkstyle ${{ steps.changed.outputs.files }} | cs2pr
48+
49+
# tests/ is excluded from the main ruleset on purpose (WordPress-Docs
50+
# would demand docblocks across 420 files). Indentation is the one thing
51+
# that is enforced there, over the whole directory rather than only
52+
# changed files — it is fast, and an invariant that only holds for files
53+
# a PR happens to touch is not an invariant.
54+
- name: Run PHPCS indentation check on tests/
55+
run: |
56+
vendor/bin/phpcs -q --report=checkstyle --standard=phpcs-tests.xml.dist | cs2pr

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ The format follows [Keep a Changelog] (https://keepachangelog.com/en/1.1.0/).
77

88
## [Unreleased]
99

10+
### Changed
11+
- Internal (#1005) — **`tests/` is tab-indented, and now enforced**: 250 space-indented files against 170 tab-indented ones, with nothing checking either, so a reformat alone would have drifted back. Reindented, plus a two-sniff `phpcs-tests.xml.dist` over the whole directory. No test logic changed.
12+
1013
## [6.20.1] (2026-08-30) — `f1e4134`
1114

1215
### Added

‎CLAUDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ It proves only that both ends of the wire exist and agree on a name — not that
262262
- jsdom has no layout — jQuery `:visible` always reports false for shown elements. Assert on `css('display')` instead. Disable jQuery animation queueing in tests by setting `window.$.fx.off = true` in `beforeEach` so `slideUp`/`slideDown`/`fadeOut` apply immediately.
263263
- **pcov coverage-attribution gotcha (PHP).** pcov does not attribute coverage to a class first autoloaded *during* a test method, so a freshly-extracted class can report 0% even when fully exercised — this repeatedly bit the #563 repository/god-class splits. Fix: add `@covers \FQCN` to the test class **and** preload the class with `class_exists( '\\FQCN' )` in `setUp()` (right after `Monkey\setUp()`). Spot-check attribution with `php -d pcov.enabled=1 -d pcov.directory=./includes vendor/bin/phpunit --coverage-clover /tmp/cov.xml --filter <Test>`.
264264
- **`templates/` is outside the coverage scope.** `phpunit.xml` includes only `./includes` for coverage, so extracting inline markup from a god-class into `templates/*.php` partials reduces the class without touching the coverage floor (the F1/F2 lesson). Logic stays in `includes/` (and stays covered); pure markup moves to `templates/`.
265+
- **`tests/` is tab-indented, and that is enforced.** `phpcs.xml.dist` excludes `tests/` on purpose — `WordPress-Docs` would demand a file, class and method docblock in all 420 files. Indentation is the one exception: `phpcs-tests.xml.dist` carries exactly two sniffs (`DisallowSpaceIndent`, `ScopeIndent`) and runs over the whole directory in the PHPCS workflow. The suite was 249 space-indented files against 170 tab-indented ones with nothing enforcing either, so a one-off reformat would have drifted back; the gate is what makes the reindent worth doing. Do not widen that ruleset — line length, docblocks, naming and Yoda conditions are how it stops being cheap.
265266
- **Running the suite locally.** Install pcov once (`apt-get install -y --no-install-recommends php8.4-pcov`); the full suite is ~10 min. Scope while iterating with `vendor/bin/phpunit --filter <Test>`; `vendor/bin/phpstan analyse --no-progress <path>` and `vendor/bin/phpcs --standard=phpcs.xml.dist -q <files>` (auto-fix with `vendor/bin/phpcbf`) reproduce the PHPStan/WPCS gates.
266267
- **PHPStan/phpdoc idioms.** Put `@phpstan-type` on the **class** docblock (not the file docblock); consumers use `@phpstan-import-type X from Y` on their own class docblock. Avoid `@todo (` and other `@tag (` openings — phpdoc parses the `(` and errors; use prose instead.
267268

‎phpcs-tests.xml.dist‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="ffcertificate-tests">
3+
<description>
4+
Indentation only, for tests/.
5+
6+
The main ruleset excludes tests/ (phpcs.xml.dist), and that exclusion
7+
stays: WordPress-Docs would demand a file, class and method docblock in
8+
every one of 420 test files, which is a project rather than a cleanup.
9+
10+
What it does not stay for is indentation. The suite was split 249 files
11+
on four spaces against 170 on tabs, and nothing enforced either — so it
12+
would have drifted back the week after any one-off reformat. These two
13+
sniffs are the whole ruleset: pay the reindent once, then keep it.
14+
15+
Deliberately NOT added here: line length, docblocks, naming, Yoda
16+
conditions, or anything else from WordPress-Extra. Widening this file is
17+
how it stops being cheap.
18+
</description>
19+
20+
<file>tests</file>
21+
22+
<arg name="basepath" value="."/>
23+
<!--
24+
Required: without it PHPCS measures a tab as a single column, so every
25+
tab-indented line reports as "expected 1 tabs, found 1 spaces" and the
26+
whole suite fails. The main ruleset never needed it explicitly: WPCS
27+
sets it inside WordPress-Core. This one references only Generic
28+
sniffs, so nothing sets it for us.
29+
-->
30+
<arg name="tab-width" value="4"/>
31+
<arg name="extensions" value="php"/>
32+
<arg name="colors"/>
33+
<arg name="parallel" value="8"/>
34+
<arg value="ps"/>
35+
36+
<!-- Tabs, not spaces. -->
37+
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
38+
39+
<!-- One tab per scope level, tabs counted as four columns. -->
40+
<rule ref="Generic.WhiteSpace.ScopeIndent">
41+
<properties>
42+
<property name="indent" value="4"/>
43+
<property name="tabIndent" value="true"/>
44+
</properties>
45+
</rule>
46+
</ruleset>

0 commit comments

Comments
 (0)