Skip to content
Pest Flow
Esc
↑↓navigate↵open⌘Jpreview
On this page

Introduction

Write readable Pest tests as executable behaviour specifications.

Pest Flow adds a small behaviour-driven vocabulary to ordinary Pest tests. Use it to group a capability into business rules, describe each rule with executable scenarios, and organize setup, actions, and expectations into steps.

Feature
└── Rule
    └── Scenario
        ├── Given
        ├── When
        └── Then

Pest still discovers and runs each scenario as a normal test. You keep Pest’s assertions, lifecycle hooks, test runner, and failure output. Pest Flow records features, rules, scenarios, steps, identifiers, source locations, execution statuses, durations, and captured exceptions for PHP code to inspect.

Choose a starting point

How a scenario reads

feature('Checkout', function (): void {
    rule('Discounts reduce the order total', function (): void {
        scenario('Applies a fixed discount', function (): void {
            given('an order worth 120 dollars', function (): void {
                $this->subtotal = 120;
            });

            when('a discount of 12 dollars is applied', function (): void {
                $this->total = $this->subtotal - 12;
            });

            then('the total is 108 dollars', function (): void {
                expect($this->total)->toBe(108);
            });
        });
    });
});

Each step runs in order on the same Pest test context. The values set in Given are available in When and Then, and an ordinary Pest expectation determines whether the scenario passes.

Learn in order

Install and run a scenario

Follow the quickstart to add the package and run a Pest test.

Walk through a complete example

The first scenario walkthrough explains the feature, rule, scenario, and step callbacks line by line.

Look up the API

Use the DSL reference for function behavior and core concepts for how Pest Flow fits into Pest.

Inspect discovered behavior

Was this page helpful?