PHPackages                             stateforge/scenario-core - 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. stateforge/scenario-core

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

stateforge/scenario-core
========================

Core library for declarative, attribute-driven scenario orchestration for reproducible test data states in PHP.

1.1.0(2mo ago)26.1k↑1011.9%2BSD-3-ClausePHPPHP &gt;=8.2CI passing

Since Apr 6Pushed 3w ago1 watchersCompare

[ Source](https://github.com/laloona/scenario-core)[ Packagist](https://packagist.org/packages/stateforge/scenario-core)[ Docs](https://github.com/laloona/scenario-core)[ RSS](/packages/stateforge-scenario-core/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (4)Versions (7)Used By (2)

[![Stateforge\Scenario\Core](docs/scenario.png)](docs/scenario.png)

[![CI](https://github.com/laloona/scenario-core/actions/workflows/ci.yml/badge.svg)](https://github.com/laloona/scenario-core/actions/workflows/ci.yml/badge.svg)[![PHPStan](https://camo.githubusercontent.com/022b70e6631d055205dfebf2aa7e53b3f63e7a3ea04a18e86429f279e29a29f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e)](https://camo.githubusercontent.com/022b70e6631d055205dfebf2aa7e53b3f63e7a3ea04a18e86429f279e29a29f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e)[![Stability](https://camo.githubusercontent.com/ab8ef3fe8abaa0d51cd12f22a8a8159f8022515a030b700ab4a35367d281028f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73746162696c6974792d737461626c652d627269676874677265656e)](https://camo.githubusercontent.com/ab8ef3fe8abaa0d51cd12f22a8a8159f8022515a030b700ab4a35367d281028f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73746162696c6974792d737461626c652d627269676874677265656e)[![Latest Version](https://camo.githubusercontent.com/df62e051364e75bd5bd41c16d002a846b7a777f1cdd29896563f3533046eefb3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7374617465666f7267652f7363656e6172696f2d636f7265)](https://camo.githubusercontent.com/df62e051364e75bd5bd41c16d002a846b7a777f1cdd29896563f3533046eefb3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7374617465666f7267652f7363656e6172696f2d636f7265)[![PHP Version](https://camo.githubusercontent.com/e8852815b012748b57af768cd05d52ffe5921df3aa6bb909a436a2fd813d25f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7374617465666f7267652f7363656e6172696f2d636f7265)](https://camo.githubusercontent.com/e8852815b012748b57af768cd05d52ffe5921df3aa6bb909a436a2fd813d25f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7374617465666f7267652f7363656e6172696f2d636f7265)[![License](https://camo.githubusercontent.com/c890e1a3bdba7c4425e7828d935d142273eda12a6f94f1bd56c493b9186f1aa9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c616c6f6f6e612f7363656e6172696f2d636f7265)](https://camo.githubusercontent.com/c890e1a3bdba7c4425e7828d935d142273eda12a6f94f1bd56c493b9186f1aa9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c616c6f6f6e612f7363656e6172696f2d636f7265)

---

Scenario Core
=============

[](#scenario-core)

Scenario Core is a declarative, attribute-driven framework for reproducible data states in PHP. It replaces manual test setup and fixture orchestration with structured, metadata-based scenario execution.

Requirements
------------

[](#requirements)

Scenario Core requires the following:

- PHP &gt;= 8.2.
- ext-dom \*
- [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) &gt;= 11

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

[](#installation)

> This package is intended for test and development use only.

Install it via Composer as a development dependency.

```
composer require --dev stateforge/scenario-core
```

PHPUnit Integration
-------------------

[](#phpunit-integration)

It integrates seamlessly with PHPUnit-based test suites and console tooling. To enable scenario processing in your test suite, register the PHPUnit extension in your `phpunit.xml`:

```

```

The extension integrates with the PHPUnit lifecycle and ensures that all scenario-related attributes are processed before test execution.

Defining a Scenario
-------------------

[](#defining-a-scenario)

A scenario represents a reproducible application data state. Scenarios:

- Implement `ScenarioInterface`
- Are marked with `#[AsScenario]`
- Are automatically discovered and registered

```
use Stateforge\Scenario\Core\Attribute\AsScenario;
use Stateforge\Scenario\Core\Contract\ScenarioInterface;

#[AsScenario('my-scenario')]
final class MyScenario implements ScenarioInterface
{
    public function up(): void
    {
        // load some data
    }

    public function down(): void
    {
        // remove loaded data
    }
}
```

No manual registry interaction is required.

Applying a Scenario in a Unit Test
----------------------------------

[](#applying-a-scenario-in-a-unit-test)

Scenarios can be applied declaratively using the `#[ApplyScenario]` attribute:

```
use Stateforge\Scenario\Core\Attribute\ApplyScenario;

#[ApplyScenario('my-scenario')]
final class MyTest extends TestCase
{
    #[ApplyScenario('my-second-scenario')]
    public function testSomethingImportant(): void
    {
        // scenario has already been applied, data can be tested
    }
}
```

Multiple scenarios may be applied at class or method level. A scenario class can apply other scenarios.

Example Use Case
----------------

[](#example-use-case)

```
#[ApplyScenario(UserExists::class, [ 'id' => 42 ])]
#[ApplyScenario(UserHasSubscription::class, [ 'id' => 42 ])]
final class SubscriptionTest extends TestCase
{
    public function testUserHasAccess(): void
    {
        // system is already in the desired state
        $this->assertTrue($this->service->userHasAccess(42));
    }
}
```

Resetting the Database
----------------------

[](#resetting-the-database)

Use the `#[RefreshDatabase]` attribute to reset the database before scenario execution:

```
use Stateforge\Scenario\Core\Attribute\RefreshDatabase;

#[RefreshDatabase]
final class MyFreshDatabaseTest extends TestCase
{
}
```

This ensures clean and deterministic test state. This can be applied on class or method level and on Unit Tests or Scenario Classes.

> The `#[RefreshDatabase]` attribute triggers a database reset hook. Scenario Core itself does not implement database logic, as it remains framework-agnostic. Instead, a custom PHP file can be configured to perform the reset according to your application's infrastructure.

Console Usage
-------------

[](#console-usage)

Scenarios can also be executed directly from the console:

```
php vendor/bin/scenario apply my-scenario
```

This allows:

- local state setup
- reproducible development fixtures
- CI preparation workflows

Get all available CLI Commands:

```
php vendor/bin/scenario
```

Framework Integration
---------------------

[](#framework-integration)

Scenario Core is framework-agnostic and can be integrated into any PHP application.

It works particularly well with:

- Symfony-based applications: ([stateforge/scenario-symfony](https://github.com/laloona/scenario-symfony))
- Laravel-based applications: ([stateforge/scenario-laravel](https://github.com/laloona/scenario-laravel))
- Custom test infrastructures using PHPUnit

Framework-specific integration layers may be provided separately.

Next Steps
----------

[](#next-steps)

- [Getting Started](docs/getting-started.md)
- [Configuration](docs/configuration.md)
- [Scenarios](docs/scenarios.md)
- [Parameter Types](docs/parameter-types.md)
- [CLI Usage](docs/cli.md)
- [Testing with PHPUnit](docs/testing-with-phpunit.md)
- [Recipes](docs/recipes.md)

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance91

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

6

Last Release

21d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/14c160ba8dd9d6012afbd54bd9cbd59c72cfc963a68c820589c8c01fa9c5c7ea?d=identicon)[laloona](/maintainers/laloona)

---

Top Contributors

[![laloona](https://avatars.githubusercontent.com/u/5313072?v=4)](https://github.com/laloona "laloona (201 commits)")

---

Tags

testingphpunitfixturesstatescenariotest data

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stateforge-scenario-core/health.svg)

```
[![Health](https://phpackages.com/badges/stateforge-scenario-core/health.svg)](https://phpackages.com/packages/stateforge-scenario-core)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k136.1M984](/packages/brianium-paratest)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69619.8M640](/packages/spatie-phpunit-snapshot-assertions)[allure-framework/allure-phpunit

Allure PHPUnit integration

6913.4M46](/packages/allure-framework-allure-phpunit)[facile-it/paraunit

paraunit

145845.1k17](/packages/facile-it-paraunit)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

77559.8k16](/packages/robiningelbrecht-phpunit-pretty-print)[shopsys/http-smoke-testing

HTTP smoke test case for testing all configured routes in your Symfony project

67270.5k2](/packages/shopsys-http-smoke-testing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
