Skip to content

RuleStep ​

Rasuvaeff\PropertyTesting\StateMachine\RuleStep

Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2

Implements: StateMachine\Command, Stringable

One step of a rule-based sequence: a Rule method and the arguments drawn for it. It is the Command the engine's sequence generation and shrinking work on, so a rule-based machine gets the same drop-and-simplify descent a hand-written command sequence does.

The model threaded through StateMachine\StateMachine::check() is the machine object itself: at generation time there is no machine yet and every step is applicable (the model is null), at run time the guard decides. The step's body is the rule method — its exception is the failed postcondition — followed by every invariant.

Constructor ​

php
__construct(
    non-empty-string $rule,
    array<string,mixed> $arguments,
    ?non-empty-string $precondition = NULL,
    list<non-empty-string> $invariants = [],
)
ParameterTypeDefaultDescription
$rulenon-empty-stringrequiredThe rule method.
$argumentsarray<string,mixed>requiredBy parameter name.
$precondition?non-empty-stringNULLThe guard method, when the rule has one.
$invariantslist<non-empty-string>[]The invariant methods, run after the rule.

Methods ​

preCondition() ​

php
preCondition(mixed $model): bool

True before a machine exists (generation), the guard's answer once it does.

  • $model — The machine, or null at generation time.

nextState() ​

php
nextState(mixed $model): mixed

The machine itself: its state is its own fields, advanced by run().

  • $model — The machine, or null at generation time.

run() ​

php
run(mixed $model, mixed $system): mixed

Runs the rule, then every invariant, against $system — the machine.

  • $model — The machine, unused: the step acts on $system, which is the same object.
  • $system — The machine.

Throws:

  • LogicException — When $system is not an object.

postCondition() ​

php
postCondition(mixed $model, mixed $result): bool

Always true: the rule's exception is the failed postcondition.

  • $model — The machine.
  • $result — What StateMachine\run() returned — null.

__toString() ​

php
__toString(): string

The step as a call: rule(name: value, ...).