Prove a Scenario
A Scenario turns green when a real run passes, and for no other reason.
Barnspek never takes anyone’s word that a story is done. A Scenario turns green only when a real run against your software passes. This page takes a Scenario from nothing to green. The commands were run, in order, in the hotel example.
How a Scenario gets its colour #
| Colour | When |
|---|---|
| Yellow | Some ticket for the Scenario is not done. |
| Green | Every ticket is done, and the last run passed. |
| Red | Every ticket is done, but the Scenario has never been run, or its last run failed. |
| No colour | It has no ticket and no run: nothing has been claimed about it yet. |
A story’s colour is rolled up from its Scenarios. It is green when every Scenario is green, red when every Scenario is red or green and at least one is red, and yellow otherwise. A story with no Scenario has no colour, and no ticket can be opened against it.
No command and no button marks a Scenario green. A result never expires on a clock: nothing turns green because time passed, and a result is replaced only by a later run. Opening a new ticket on a green Scenario drops it back to yellow and discards its last run, because the evidence predates the new work.
Open a ticket #
A ticket tracks one piece of work against one Scenario. It needs a title and a description. The reference is optional, for a ticket in another system.
$ vendor/bin/barnspek work:create reservations book-a-room-for-a-run-of-nights \
book-a-room-for-three-nights --title="Book a room" \
--description="Let a guest hold a free room" --reference=HOTEL-1
Barn: …/hotel
Created work ticket 01a1cb3e-… for scenario 01a1cb3e-…: Book a room
$ vendor/bin/barnspek work:list reservations book-a-room-for-a-run-of-nights \
book-a-room-for-three-nights
Barn: …/hotel
Scenario: book a room for three nights — yellow
id: 01a1cb3e-…
Not yet run — prove it with `scenario-bridge run`; until then it stays red.
01a1cb3e-… To do Book a room [HOTEL-1]
The arguments are the area of business, the story and the Scenario. The Scenario is yellow while its ticket is open.
Say how to run it #
A Scenario is run against Ports: small classes you fill in that connect its words to your software. Two more Composer packages generate and run them:
$ composer require --dev rmb32/port-generator rmb32/scenario-bridge
Tell the generator where to put the Ports, in .barn/barnspek/settings.json, and make sure Composer can load
them (here, by adding "autoload-dev": {"psr-4": {"App\\Tests\\": "tests/"}} to your composer.json and running
composer dump-autoload):
{"portStubs": {"directory": "tests/Spec/Port", "namespace": "App\\Tests\\Spec\\Port"}}
$ vendor/bin/port-generator generate reservations
Wrote: …/hotel/tests/Spec/Port/Reservations/Fact/Room/IsAvailableArrange.php
Wrote: …/hotel/tests/Spec/Port/Reservations/Fact/Room/IsAvailableAssert.php
Wrote: …/hotel/tests/Spec/Port/Reservations/Fact/Booking/IsConfirmedArrange.php
Wrote: …/hotel/tests/Spec/Port/Reservations/Fact/Booking/IsConfirmedAssert.php
Wrote: …/hotel/tests/Spec/Port/Reservations/Action/BookARoomForThreeNights.php
Wrote: …/hotel/tests/Spec/Port/Reservations/Role/GuestAuthenticator.php
Done — 6 written, 0 skipped (already existed).
One class is written for each fact (to set it up, and to check it), each action and each role. Until you fill them in, each one throws “TODO”, and a run says so:
$ vendor/bin/scenario-bridge run reservations book-a-room-for-three-nights
- Scenario: They will now book a room for three nights:
💥 When they book a room for three nights they expect it to be accepted but the Scenario crashed authenticating as guest: RuntimeException: TODO: implement App\Tests\Spec\Port\Reservations\Role\GuestAuthenticator::authenticate()
Recorded this run against the Scenario (failed).
A failed run is recorded too. Now fill the classes in with your real software. The action, for instance, is what the guest does:
<?php
declare(strict_types=1);
namespace App\Tests\Spec\Port\Reservations\Action;
use Override;
use Rmb32\ScenarioRunner\Api\Contract\Act;
use Rmb32\ScenarioRunner\Api\Contract\ReadStorage;
use Rmb32\ScenarioRunner\Api\Contract\WriteStorage;
use Rmb32\ScenarioRunner\Api\ValueObject\AreaOfBusiness\Role\Story\Scenario\Action\ActionData;
use Rmb32\ScenarioRunner\Api\ValueObject\AreaOfBusiness\Role\Story\Scenario\Action\OutcomeData;
final class BookARoomForThreeNights implements Act
{
#[Override]
public function act(ActionData $action, ReadStorage $readStorage, WriteStorage $writeStorage): OutcomeData
{
$nights = $action->argumentFor('nights')->value;
if ($readStorage->retrieve('room')['booked']) {
return OutcomeData::Rejected;
}
$writeStorage->store(['confirmed' => true, 'nights' => $nights], 'booking');
return OutcomeData::Accepted;
}
}
The Ports fill in four things. Arrange sets up a Given fact. Act performs the action and reports whether it was accepted or rejected. Assert checks a Then fact. Authenticate signs in as the role. In this example they use a small in-memory store; in a real project they call your application.
Run it #
$ vendor/bin/scenario-bridge run reservations book-a-room-for-three-nights
- Scenario: They will now book a room for three nights:
► RoomIsAvailable()
✅ When they book a room for three nights they expect it to be accepted and it was accepted
✅ they expect that BookingIsConfirmed()
Recorded this run against the Scenario (passed).
$ vendor/bin/barnspek work:list reservations book-a-room-for-a-run-of-nights \
book-a-room-for-three-nights
Barn: …/hotel
Scenario: book a room for three nights — yellow
id: 01a1cb3e-…
Last run passed at 2026-11-11T15:34:00+00:00.
01a1cb3e-… To do Book a room [HOTEL-1]
The run passed, but the ticket is still open, so the Scenario is still yellow. Move the ticket on:
$ vendor/bin/barnspek work:status reservations <ticket-id> in-progress
Barn: …/hotel
Ticket 01a1cb3e-… moved to In progress
$ vendor/bin/barnspek work:status reservations <ticket-id> done
Barn: …/hotel
Ticket 01a1cb3e-… moved to Done
The status is to-do, in-progress or done. With the ticket done and the run passed:
$ vendor/bin/barnspek work:list reservations book-a-room-for-a-run-of-nights \
book-a-room-for-three-nights
Barn: …/hotel
Scenario: book a room for three nights — green
id: 01a1cb3e-…
Last run passed at 2026-11-11T15:34:00+00:00.
01a1cb3e-… Done Book a room [HOTEL-1]
Green. Only the passing run made it so.
Run every Scenario of an area of business #
run-all runs them all, signing in as each role first. --summary prints a count and
--xml-report=build/report.xml writes a report for CI. Both commands also take --no-record, to try a
Scenario out without changing its colour.
$ vendor/bin/scenario-bridge run-all reservations --summary
1 passed, 0 failed, 1 total
Recorded 1 scenario run(s) against Work.
When the vocabulary changes #
If you reword or delete a fact or action after generating Ports, check reports the Ports that no longer match, or that have not been generated yet:
$ vendor/bin/port-generator check reservations
Nothing stale — every generated stub matches the captured vocabulary.
Scrap a ticket #
vendor/bin/barnspek work:delete reservations <ticket-id> removes a ticket at any time. The runs stay, so
deleting a done ticket changes no colour. Releasing a Phase deletes the done tickets of Scenarios that have been run; tickets are
disposable.