定制 stateforge/scenario-symfony 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Stateforge\Scenario\Symfony

CI PHPStan Stability Latest Version PHP Version License

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:

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.yaml package configuration
  • enables the symfony console scenario commands
  • generates the scenario.dist.xmlfor configuration
  • places the extendsion into phpunit.dist.xml or phpunit.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
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-04-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固