PHPackages                             binarysolutions/test-data-blueprints - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. binarysolutions/test-data-blueprints

ActiveLibrary[Testing &amp; Quality](/categories/testing)

binarysolutions/test-data-blueprints
====================================

Laravel package for reusable scenario-based test datasets beyond factories and seeders.

v0.1.2(2w ago)02MITPHPPHP ^8.2

Since Mar 17Pushed 2w agoCompare

[ Source](https://github.com/binarysolutionsnl/test-data-blueprints)[ Packagist](https://packagist.org/packages/binarysolutions/test-data-blueprints)[ RSS](/packages/binarysolutions-test-data-blueprints/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Laravel Test Data Blueprints
============================

[](#laravel-test-data-blueprints)

> Reusable, composable, scenario-based test datasets for Laravel.

Factories solve *object construction*. Seeders solve *bulk population*.
Neither solves the problem of named, reusable *domain scenarios* — the
"company with an active subscription and 3 admin users in the onboarding state"
you need to set up consistently across dozens of feature tests.

Blueprints fill that gap.

---

Contents
--------

[](#contents)

- [Installation](#installation)
- [Core concepts](#core-concepts)
- [Defining a blueprint](#defining-a-blueprint)
- [Steps: create, make, tap](#steps-create-make-tap)
- [Ref tokens](#ref-tokens)
- [Composition with `->use()`](#composition-with---use)
- [Time travel with `->at()`](#time-travel-with---at)
- [Snapshots and caching](#snapshots-and-caching)
- [⚠ Test isolation and RefreshDatabase](#-test-isolation-and-refreshdatabase)
- [Using in tests (PHPUnit)](#using-in-tests-phpunit)
- [Using in tests (Pest)](#using-in-tests-pest)
- [Using in local seeders](#using-in-local-seeders)
- [Artisan commands](#artisan-commands)
- [Configuration](#configuration)
- [Troubleshooting](#troubleshooting)

---

Installation
------------

[](#installation)

```
composer require binarysolutions/test-data-blueprints --dev
```

> ⚠ Always install with `--dev`. This package must not be present in production.

Optionally publish the config file:

```
php artisan vendor:publish --tag=test-data-blueprints-config
```

Blueprint files live in `database/blueprints/` by default (alongside migrations, factories, and seeders — all database-layer concerns in one place). Create the directory:

```
mkdir database/blueprints
```

---

Core concepts
-------------

[](#core-concepts)

ConceptWhat it is**Blueprint**A named, parameterisable scenario definition stored as a PHP file in `database/blueprints/`.**Step**One unit of work inside a blueprint: `->create()`, `->make()`, or `->tap()`.**Ref**A named value produced by a step and stored in the `BlueprintResult`. Later steps (and tests) access refs by name.**@ref token**A string like `'@company'` or `'@users[0].id'` that resolves to a previously stored ref at runtime.**Composition**`->use('other-blueprint')` imports all refs from another blueprint before this blueprint's own steps run.**Snapshot**In-memory caching of a `BlueprintResult` for the duration of a test process. Safe only for in-memory blueprints.---

Defining a blueprint
--------------------

[](#defining-a-blueprint)

Generate a stub:

```
php artisan make:blueprint SaasCompany
# Creates: database/blueprints/saas_company.php
# Blueprint name: saas-company
```

A blueprint file returns a `Blueprint` instance:

```
