Skip to the content
Howdah

being built · no release yet

Search

Skip the list of pages

Holding tests

Some code is run by every test: a composition root, a service provider or a kernel. Each mutant of it would run the whole suite. Declare instead which tests hold it. The path is then mutated against those tests alone, once they are shown to cover every line of it that the whole suite covers.

// A Pest test, or every test in a describe
use NightWorksIO\MutationGate\Attribute\Holds;

it('boots the kernel', #[Holds('src/Kernel.php')] function () {
    // …
});

// or, for every test in the file
describe('Kernel', function () {
    it('boots', function () {
        // …
    });
})->group('holds:src/Kernel.php');

The package registers a Pest plugin, so every Pest run, the gate's or not, puts a test with #[Holds('src/Kernel.php')] in the group holds:src/Kernel.php. pest --group=holds:src/Kernel.php runs the tests that hold the file. Beside that, the plugin acts only in runs the gate starts.

pest()->group('holds:src/Kernel.php') holds the whole file too, but it changes Pest's configuration as the file loads, so every mutant's narrowed run has to load that file (ADR-0004).

// A PHPUnit test class
use NightWorksIO\MutationGate\Attribute\Holds;

#[Holds('src/Kernel.php')]
final class KernelTest extends TestCase {}

A PHPUnit class run by Pest also needs #[Group('holds:src/Kernel.php')] beside its #[Holds], because Pest cannot add a group to a class it did not build (ADR-0005).

Holds from a holding suite

A test in a suite that tests.holding lists judges only the code it holds. Its hold adds to that code's judges and replaces none of them (ADR-0005). The held path stays part of its tree. Every test of tests.suites that covers a line of it still judges that line, and so do the holding tests that run it. Use this for slow tests, such as tests that start processes, that should judge only the code they are written for. Since none of these holds narrows, one may lie inside another: a test can hold a whole directory while another holds one file in it. A hold from tests.suites still may not lie inside any other hold, nor hold one inside it.

The coverage map keeps a holding test only on the lines it runs inside the paths it holds. A hold whose tests run no line of its path stops the run with exit code 2. Under Pest, these holds need pest.patch, because Pest takes no coverage map from the gate without it.