stateforge / scenario-symfony
Symfony adapter for Stateforge Scenario Core – declarative, attribute-driven scenario execution for reproducible application state.
Package info
github.com/laloona/scenario-symfony
Type:symfony-bundle
pkg:composer/stateforge/scenario-symfony
Requires
- php: >=8.2
- doctrine/doctrine-bundle: ^2.10
- doctrine/orm: ^2.16 || ^3.0
- stateforge/scenario-core: ^1.0
- symfony/console: ^6.4 || ^7.0
- symfony/dotenv: ^6.4 || ^7.0
- symfony/finder: ^6.4 || ^7.0
- symfony/framework-bundle: ^6.4 || ^7.0
- symfony/messenger: ^6.4 || ^7.0
- symfony/yaml: ^6.4 || ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.60
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.0
README
Symfony integration for Stateforge Scenario Core.
This package provides framework-specific integration for Symfony applications, enabling seamless scenario execution within PHPUnit tests and console workflows.
It builds on top of stateforge/scenario-core and integrates with the Symfony runtime
and Doctrine ORM.
Requirements
Scenario Symfony requires the following:
- PHP >= 8.2.
- Symfony 6.4+ or 7+
- stateforge/scenario-core
Installation
This package is intended for test and development use only.
composer require --dev stateforge/scenario-symfony
After installation, run the setup command:
php bin/console scenario:install
The installation command generates the required configuration files:
- creates the
scenario.yamlpackage configuration - enables the symfony console scenario commands
- generates the
scenario.dist.xmlfor configuration - places the extendsion into
phpunit.dist.xmlorphpunit.xml
What This Package Provides
Scenario Symfony integrates Scenario Core with:
- Symfony’s service container
- Doctrine ORM (for database reset handling)
- Symfony Console
- Symfony test kernel lifecycle
Enabling the Bundle
Register the bundle in your Symfony application:
// config/bundles.php return [ Stateforge\Scenario\Symfony\ScenarioSymfonyBundle::class => ['dev' => true, 'test' => true], ];
The bundle automatically:
- registers attribute handlers
- wires scenario services
- configures database reset handling
- integrates with PHPUnit extension
Database Reset (Doctrine Integration)
When using #[RefreshDatabase], the Symfony integration resets the database using Doctrine.
The default behavior:
- recreate the database
- executed all migrations
Applying Scenarios in Unit Tests
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
}
}
Console Commands
Scenario Symfony registers dedicated console commands within your Symfony application.
You can discover them using:
php bin/console list scenario