stateforge/scenario-symfony
Composer 安装命令:
composer require --dev stateforge/scenario-symfony
包简介
Symfony adapter for Stateforge Scenario Core – declarative, attribute-driven scenario execution for reproducible application state.
README 文档
README
Scenario Symfony
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
Next Steps
统计信息
- 总下载量: 320
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-04-04
