macpaw / behat-doctrine-fixtures
用于创建 Doctrine fixture 的 Bundle
v3.0
2024-06-04 10:51 UTC
Requires
- php: ^7.4 || ^8.0
- behat/behat: ^3.0
- doctrine/dbal: ^2.0 || ^3.0
- doctrine/doctrine-bundle: ^2.0
- doctrine/doctrine-fixtures-bundle: ^3.0
- doctrine/doctrine-migrations-bundle: ^3.0
- doctrine/orm: ^2.0 || ^3.0
- symfony/dependency-injection: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^4.4 || ^5.4 || ^6.0 || ^7.0
- theofidry/alice-data-fixtures: ^1.0
Requires (Dev)
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^7.0
- squizlabs/php_codesniffer: ^3.6
- symfony/console: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/property-access: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symplify/config-transformer: ^12.3
This package is auto-updated.
Last update: 2024-09-16 12:45:43 UTC
README
从 1.x 迁移到 2.0
安装
步骤 1:安装 Bundle
打开命令行界面,进入您的项目目录并执行以下命令
$ composer require --dev macpaw/behat-doctrine-fixtures
此命令要求您全局安装了 Composer,如 Composer 文档中的安装章节所述。
如果您使用 PostgreSQL 数据库,还需要安装 postgresql-client
$ apt-get install -y postgresql-client
步骤 2:启用 Bundle
然后,通过将其添加到项目 app/AppKernel.php
文件中注册的 Bundle 列表中来启用该 Bundle
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... BehatDoctrineFixtures\BehatDoctrineFixturesBundle::class => ['test' => true] ); // ... } // ... }
步骤 3:创建 Behat Doctrine Fixtures 配置
config/packages/test/behat_doctrine_fixtures.yaml
配置 behat 数据库上下文
behat_doctrine_fixtures: connections: default: database_fixtures_paths: - <path to directory with your fixtures>
您不需要在此处显式传递数据库 URL,因为此 Bundle 在底层使用 doctrine 连接。目前,我们支持 PostgreSQL 和 Sqlite 数据库。
如果您想在项目中使用多个数据库,只需在 behat_doctrine_fixtures.connections
下添加另一个连接及其自己的配置即可
behat_doctrine_fixtures: connections: default: database_fixtures_paths: - <path to directory with your fixtures> <secondConnectionName>: run_migrations_command: <customMigrationsCommand> database_fixtures_paths: - <path to directory with your fixtures>
步骤 4:配置 Behat
转到 behat.yml
... contexts: - BehatDoctrineFixtures\Context\DatabaseContext ...