Skip to content

Command

Rasuvaeff\PropertyTesting\StateMachine\Command

InterfaceSource

A single operation in a stateful / model-based test.

A command bundles the four responsibilities of model-based testing: whether it may run in a given model state (preCondition()), how the model evolves (nextState()), how the real system executes it (run()), and how the observed result is checked against the model (postCondition()). Sequences of commands are generated by \Rasuvaeff\PropertyTesting\Gen::commands() and driven by StateMachine::check().

The model is an immutable value threaded through the sequence: nextState() must return the new model rather than mutate the given one, so the runner and the generator can replay it deterministically. preCondition(), nextState() and postCondition() must be pure — only run() touches the system under test.

Methods

preCondition()

php
preCondition(mixed $model): bool

May this command run in the given (pre-state) model? Gates both generation and, during replay, whether the runner executes or skips the command.

nextState()

php
nextState(mixed $model): mixed

The model's expected state after this command. Pure; returns the new model and never touches the system under test.

run()

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

Execute this command against the system under test and return the observed result for postCondition() to check. The pre-state model is provided for commands whose action depends on it.

postCondition()

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

Verify the observed result against the pre-state model. Return false (or throw) to falsify the property.