Skip to content

Define your modules

Configure Larch once, in tests/Pest.php. Every rule of the run uses this configuration.

When each module is a namespace under one parent, give the parent with \*:

tests/Pest.php
use function Nwidart\Larch\larch;
larch()->modules('App\Domain\*');

Each namespace directly under App\Domain is a module, named by that namespace: App\Domain\Billing is Billing.

With nwidart/laravel-modules installed, call modules() with no argument. It uses Modules\*:

tests/Pest.php
larch()->modules();

nwidart/laravel-modules defines a global module() helper. Import Larch’s functions with use function in each test file, so PHP does not call the global one:

use function Nwidart\Larch\module;
use function Nwidart\Larch\modules;

When modules do not share a parent namespace, name each one:

tests/Pest.php
larch()->modules([
'Billing' => 'App\Billing',
'Catalog' => 'App\Catalog',
'Shared' => 'Support\Shared',
]);

The public API is the part of a module other modules may use. List its namespaces, relative to each module:

tests/Pest.php
larch()
->modules('Modules\*')
->publicApi('Contracts', 'Events', 'Data');

Contracts means Modules\Billing\Contracts for Billing, and Modules\Catalog\Contracts for Catalog. Without publicApi(), the public API is Contracts and Events.

Larch reads every PSR-4 folder of the project outside vendor. To read only some folders:

tests/Pest.php
larch()->paths('app', 'Modules');

Larch skips folders named vendor, node_modules, tests and Tests wherever they appear. To skip other folders, replace that list:

tests/Pest.php
larch()->exclude('vendor', 'node_modules', 'tests', 'Tests', 'Legacy');