Skip to content

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

Open
YvesCesar wants to merge 2 commits into
test/e2e-playwrightfrom
test/structure-and-coverage
Open

YvesCesar wants to merge 2 commits into
test/e2e-playwrightfrom
test/structure-and-coverage

Conversation

@YvesCesar

@YvesCesar YvesCesar commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

The tests mirror the theme files by name, but nothing checked it, and nothing stopped the line coverage from going down. This adds both.

Test layout

tests/Unit/StructureTest.php checks, in both directions:

  • every PHP file in inc/, src/ and woocommerce/ has a test named after it at the same path, with each folder and file name in StudlyCase: inc/cpf-cnpj.php → tests/Integration/Inc/CpfCnpjTest.php, woocommerce/myaccount/form-login.php → tests/Integration/Woocommerce/Myaccount/FormLoginTest.php, and src/TaxId.php → tests/Unit/TaxIdTest.php or tests/Integration/TaxIdTest.php. Files in inc/ and woocommerce/ need WordPress, so only an integration test covers them: loading one without WordPress stops at defined( 'ABSPATH' ) || exit;;
  • every *Test.php under tests/Unit and tests/Integration, and every *.spec.ts under tests/E2E, points to a file that exists, turning each folder and file name back to kebab case (Woocommerce/SingleProduct/Tabs/DescriptionTest.php → woocommerce/single-product/tabs/description.php). A browser test may also cover a class in src/.

A missing test fails with the file and the test paths it looked for, for example src/Logo.php is not covered by tests/Unit/LogoTest.php or tests/Integration/LogoTest.php. It runs in the unit suite, without WordPress; tests/Support/ThemeFiles.php lists the files.

Coverage

  • phpunit-coverage.xml.dist runs the unit and integration suites together, and composer coverage writes tests/.coverage/clover.xml (ignored).
  • A Coverage job in phpunit.yml runs it on PHP 8.3 with Xdebug and hands the report to octocov (k1LoW/octocov-action, pinned by SHA). .octocov.yml fails the run when line coverage is below 90% or below the last report of main, kept as a workflow artifact.
  • The line coverage is 93.6% (1075 of 1148 lines). What is left out is the fallback for a site without WooCommerce, the Polylang calls (Polylang is not loaded in the suite), the lost password page, which ends with exit and is covered by the browser test, and functions.php and inc/theme-setup.php, which run while WordPress boots, before coverage is recorded.

readme.txt states the layout rule and the coverage floor.

Verification

  • composer ci passes: 140 unit tests (36 of them from StructureTest) and 167 integration tests. composer coverage passes as well, also in random order.
  • Removing tests/Unit/LogoTest.php, adding an empty tests/Integration/Inc/OrphanTest.php or tests/E2E/Nothing.spec.ts, or adding woocommerce/single-product/price.php without a test makes StructureTest fail for each, naming the paths. A woocommerce/single-product/tabs/description.php override with its test, and tests/E2E/Logo.spec.ts, pass.
  • The acceptance rule is applied: running octocov v0.80.1 on this report as in CI, current >= 99% && current >= prev fails with "code coverage is 93.6%. the condition in the coverage.acceptable: section is not met", and the configured current >= 90% && current >= prev passes. Without a report of main yet, prev is 0, so only the floor applies until the first run on main.

Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
… to src

Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
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.

1 participant