Bootloader code is not covered: the app boots before the coverage interceptor

Open
#96 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
php
Domain
testing

Research direction

Read src/Stage.php and src/Internal/Interceptor/BootInterceptor.php, then compare the boot interceptor order with Testo's InterceptorOptions::ORDER_COVERAGE. Reproduce with a package test case extending Spiral\Testing\TestCase and a bootloader in defineBootloaders(), collecting line coverage or Infection results. Done when bootloader init()/boot() lines are attributed to each test and their mutants are included in mutation testing.

Written by the indexing model from the issue text.

Description

bug

Description

With spiral/testing 4.x the application boots outside Testo's coverage window, so code run in bootloader init()/boot() is not credited to any test. In spiral-packages/symfony-validator, migrating the Functional suite from a hand-rolled kernel (booted in the test body via #[BeforeTest]) to Spiral\Testing\TestCase dropped line coverage from 99/99 to 92/99: the missing lines are all in ValidatorBootloader. Infection is affected silently: it generated 50 mutants instead of 53 (the bootloader lines have no covering test, so their mutants are never produced) and still reported 100% MSI.

The cause is interceptor order. BootInterceptor runs at Stage::BOOT = 300_000 (src/Stage.php#L27, src/Internal/Interceptor/BootInterceptor.php#L18), while the coverage interceptor sits at InterceptorOptions::ORDER_COVERAGE = 1_001_000_000 (testo core/Pipeline/Attribute/InterceptorOptions.php#L51), i.e. inner to the boot. Everything the app does while booting happens before coverage collection starts.

Steps to reproduce

  1. A package test suite extending Spiral\Testing\TestCase, with the package bootloader in defineBootloaders().
  2. Run Testo with coverage (or Infection via testo/bridge-infection).
  3. The bootloader's init()/boot() lines are reported as uncovered, although every test boots them.

Workaround: call $this->initApp() inside the test body; the second boot runs inside the coverage window.

Proposed solution

Make the boot visible to coverage, e.g. by booting inside the coverage window (an order inner to ORDER_COVERAGE) or by attributing the boot to the test some other way. A boot that runs once per test should count as that test's coverage, otherwise mutation testing silently loses mutants instead of reporting them as uncovered.

Dominant language
PHP
Stars
7
Forks
7
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spiral/testing

All issues in spiral/testing

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.