Skip to content

Adopt Larch in an existing app

An existing app breaks rules on its first run. A baseline accepts those violations, so CI fails only on new ones.

  1. Write your rules. Run them once to see what they find.

  2. Write the baseline:

    Terminal window
    ./vendor/bin/pest tests/Arch --update-larch-baseline

    Larch writes larch-baseline.json at the project root.

  3. Commit larch-baseline.json.

From now on, a test fails only on violations that are not in the baseline. The failure message says how many more are in the baseline.

After the tests, Larch lists the baseline entries of passing tests that no violation matches any more. To remove them, run Pest with --update-larch-baseline again and commit the file.

--update-larch-baseline keeps the entries of the tests that fail. To start over, delete the file first:

Terminal window
rm larch-baseline.json
./vendor/bin/pest tests/Arch --update-larch-baseline
tests/Pest.php
larch()->baseline('tests/Arch/baseline.json');

--update-larch-baseline works with --parallel. The lines Larch prints after the tests are missing then, because each worker keeps its own count.