Guard module boundaries
Write module rules in Pest’s arch() tests, for example in tests/Arch/ModulesTest.php.
Define your modules first.
Limit what a module may use
Section titled “Limit what a module may use”To list the modules a module may use, use toOnlyDependOn():
use function Nwidart\Larch\module;
arch('billing uses only shared and catalog') ->expect(module('Billing')) ->toOnlyDependOn(module('Shared'), module('Catalog'));To allow only the public API of a module, pass module('Name')->publicApi():
arch('billing uses only shared, and the public API of catalog') ->expect(module('Billing')) ->toOnlyDependOn(module('Shared'), module('Catalog')->publicApi());To forbid a module to use any other module, call toOnlyDependOn() with no target:
arch('shared uses no other module') ->expect(module('Shared')) ->toOnlyDependOn();Keep internals internal
Section titled “Keep internals internal”To make every module use the others only through their public API, use toOnlyUsePublicApis() on modules():
use function Nwidart\Larch\modules;
arch('modules use each other only through their public API') ->expect(modules()) ->toOnlyUsePublicApis();To check one module only, give module('Name') as the subject.
Forbid cycles
Section titled “Forbid cycles”To fail when modules use each other, directly or through other modules, use toHaveNoCycles():
arch('no module is in a cycle') ->expect(modules()) ->toHaveNoCycles();Check more than imports
Section titled “Check more than imports”These rules check the classes the code names. To check facades, container keys, events and jobs too,
add via(). See Check links the app makes.