Skip to content

test: enforce the test layout and hold the line coverage - #13

Merged
vitormattos merged 9 commits into
mainfrom
test/structure-and-coverage-gate
Sep 24, 2026
Merged

vitormattos merged 9 commits into
mainfrom
test/structure-and-coverage-gate

Conversation

@YvesCesar

@YvesCesar YvesCesar commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

The conventions the suite follows were kept by review only: a new class could land without a test, and a test could outlive the file it was named after. This adds the two checks that keep them, on top of the Playwright suite from #12 (hence the base branch; it retargets to main once #9, #10, #11 and #12 are merged).

The two files that had no test

src/Autoloader.php and src/Github/WebhookDecision.php were the only source files with no test named after them, so they come first — the layout check would fail on them otherwise.

  • tests/Unit/AutoloaderTest.php — the loader lands in the stack, every class of the plugin is loaded from the file named after it, a class of another project is left alone, and a class with no file is not an error.
  • tests/Unit/Github/WebhookDecisionTest.php — the four answers a delivery can get, what each one carries, and the LogicException the three that are not a deploy throw when asked for a workflow run. Its lines were already exercised through WebhookGateTest, which is exactly why it was easy to miss.

The layout check

tests/Unit/StructureTest.php reads the repository instead of a list kept by hand (tests/Support/PluginFiles.php) and fails in both directions:

  • a file of the plugin with no test named after it — src/X.php wants tests/Unit/XTest.php or tests/Integration/XTest.php, includes/foo-bar.php wants tests/Integration/Includes/FooBarTest.php, and the main file wants tests/Integration/LibresignWpCustomizationsTest.php;
  • a test named after a file that does not exist, including .spec.ts under tests/E2E/.

The failure names both paths, so a rename that breaks the mirror says which file to move:

src/Github/Orphan.php is not covered by tests/Unit/Github/OrphanTest.php or tests/Integration/Github/OrphanTest.php.
tests/Unit/Account/StrayTest.php does not cover src/Account/Stray.php.

The coverage floor

composer coverage runs the suite with Xdebug collecting coverage and hands the clover report to bin/coverage-gate.php, which compares it with coverage-floor.txt — today 65.33, the line coverage of libresign-wp-customizations.php, includes/ and src/ as it stands.

The floor only ever goes up. Coverage below it fails; coverage a full point above it fails too, printing the number to write in the file. A change that covers more raises the floor in the same commit, and coverage that quietly drains away between releases is not possible.

Line coverage: 65.33% (floor 65.33%).
Line coverage fell to 62.10%, below the floor of 65.33%. Cover what the change left uncovered.
Line coverage rose to 66.40%, above the floor of 65.33%. Raise it: echo 66.40 > coverage-floor.txt

composer ci now ends in coverage instead of test, so one command still runs everything CI runs. The Tests workflow gains a Coverage job on PHP 8.3 with Xdebug — the same driver as the container, so the number does not move between a local run and CI.

Verification

composer ci is green: no lint, PHPCS or PHPStan findings, 299 PHPUnit tests (up from 239), and the gate at 65.33%. The layout check was confirmed against a stray file and a stray test, the output above, and all four outcomes of the gate — at the floor, below it, above it, and a floor file that does not hold a number.

@YvesCesar
YvesCesar marked this pull request as draft September 16, 2026 22:22
@YvesCesar
YvesCesar marked this pull request as ready for review September 16, 2026 22:38
@YvesCesar
YvesCesar force-pushed the test/structure-and-coverage-gate branch from 8df0fb4 to 618538d Compare September 16, 2026 23:02
@YvesCesar
YvesCesar force-pushed the test/structure-and-coverage-gate branch from 618538d to d4ff31c Compare September 17, 2026 20:59
@YvesCesar
YvesCesar force-pushed the test/structure-and-coverage-gate branch 2 times, most recently from f8a4d8e to 644bf2a Compare September 17, 2026 21:34
Base automatically changed from test/e2e-playwright to refactor/decision-logic-in-src September 18, 2026 20:39
Base automatically changed from refactor/decision-logic-in-src to test/integration-harness September 18, 2026 20:49
Comment thread bin/coverage-gate.php Outdated
@vitormattos
vitormattos added this pull request to stack #14 September 19, 2026 17:59
vitormattos
vitormattos previously approved these changes Sep 19, 2026

@vitormattos vitormattos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me now.

Base automatically changed from test/integration-harness to main September 24, 2026 02:07
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
@vitormattos
vitormattos force-pushed the test/structure-and-coverage-gate branch from 155c5f8 to 0fb050f Compare September 24, 2026 02:07
@vitormattos
vitormattos merged commit 32f3cdc into main Sep 24, 2026
7 checks passed
@vitormattos
vitormattos deleted the test/structure-and-coverage-gate branch September 24, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants