App rules
App rules read the booted app. Each one takes one subject.
| Expectation | Subject | Baseline kind |
|---|---|---|
toUseMiddleware() |
larch()->routes() |
middleware |
toHavePolicy() |
larch()->models() |
policy |
toDefine() |
larch()->jobs() |
define |
toBeQueued() |
larch()->listenersOf() |
queued |
toBeInMorphMap() |
larch()->models() |
morph-map |
toUseMiddleware()
Section titled “toUseMiddleware()”expect(larch()->routes())->toUseMiddleware(string ...$middleware)Fails when a route does not run one of the middleware. Each middleware is one of:
- A name with its parameters:
auth:sanctum. A name without parameters, such asauth, also matchesauth:sanctum. - A group:
api. A group counts only when the route declares it andwithoutMiddleware()removes none of its members. - A class.
Each route: its methods and URI, its action, and the middleware it declares.
toHavePolicy()
Section titled “toHavePolicy()”expect(larch()->models())->toHavePolicy()Fails when Laravel finds no policy for a model, registered with Gate::policy() or found by name.
toDefine()
Section titled “toDefine()”expect(larch()->jobs())->toDefine(string ...$members)Fails when a job does not declare a member in a form the queue reads:
- A property.
- A queue attribute, such as
#[Tries(3)], fortries,timeout,backoff,maxExceptionsandretryUntil. - A method, for
tries,backoffandretryUntil.
toBeQueued()
Section titled “toBeQueued()”expect(larch()->listenersOf('App\Events\*'))->toBeQueued()Fails when a listener of a matching event:
- does not implement
ShouldQueue, or - is registered as an object. Laravel calls such a listener at once, even when it implements
ShouldQueue.
toBeInMorphMap()
Section titled “toBeInMorphMap()”expect(larch()->models()->usedInMorphs())->toBeInMorphMap()Fails when a model has no alias in the morph map set with Relation::morphMap() or Relation::enforceMorphMap().