theofidry/alice-bundle-extension

此包已被 弃用 且不再维护。未建议替代包。

用于加载 HautelookAliceBundle 固定文件的扩展。

v1.3.1 2016-06-07 14:53 UTC

This package is auto-updated.

Last update: 2022-10-02 00:28:16 UTC


README

一个用于加载 HautelookAliceBundle 固定文件的 Behat 扩展Behat extension

Package version Build Status SensioLabsInsight Scrutinizer Code Quality

安装

您可以使用 Composer 将此包安装到您的项目中

composer require --dev theofidry/alice-bundle-extension

然后,在您的 behat 配置文件 behat.yml 中注册扩展并声明上下文

# behat.yml
default:
    suites:
        default:
            contexts:
                - Fidry\AliceBundleExtension\Context\Doctrine\AliceORMContext

                # or if you want to set the base path only for this context:
                - Fidry\AliceBundleExtension\Context\Doctrine\AliceORMContext:
                    basePath: %paths.base%/tests/Features/fixtures/ORM (default value)
    # ...
    extensions:
        Fidry\AliceBundleExtension\Extension:
            fixtures_base_path: ~ # default to %paths.base%/features/fixtures

您有三个可用的上下文

  • Fidry\AliceBundleExtension\Context\Doctrine\AliceODMContext
  • Fidry\AliceBundleExtension\Context\Doctrine\AliceORMContext
  • Fidry\AliceBundleExtension\Context\Doctrine\AlicePHPCRContext

默认的固定文件基本路径分别为

  • %paths.base%/tests/Features/fixtures/ODM
  • %paths.base%/tests/Features/fixtures/ORM
  • %paths.base%/tests/Features/fixtures/PHPCR

基本用法

假设您与安装部分相同的配置,您可以创建以下固定文件

# features/fixtures/ORM/dummy.yml

AppBundle\Entity\Dummy:
    dummy_{1..10}:
        name: <name()>

然后只需使用以下步骤加载您的固定文件

Given the fixtures file "dummy.yml" is loaded
Given the fixtures file "dummy.yml" is loaded with the persister "doctrine.orm.entity_manager"
Given the following fixtures files are loaded:
  | fixtures1.yml |
  | fixtures2.yml |

加载固定文件参数

固定文件参数可以像加载固定文件一样加载。任何可以加载固定文件的可用步骤也可以加载参数。您必须在依赖的固定文件之前加载您的参数

Given the fixtures file "parameters.yml" is loaded
And the fixtures file "dummy.yml" is loaded

步骤

对于每个上下文,您有以下可用的步骤

@Given the database is empty
@Then I empty the database

@Given the fixtures "fixturesFile" are loaded
@Given the fixtures file "fixturesFile" is loaded
@Given the fixtures "fixturesFile" are loaded with the persister "persister_service_id"
@Given the fixtures file "fixturesFile" is loaded with the persister "persister_service_id"
@Given the following fixtures files are loaded:
  | fixtures1.yml |
  | fixtures2.yml |
@Given the following fixtures files are loaded with the persister "persister_service_id":
  | fixtures1.yml |
  | fixtures2.yml |

加载固定文件可以按照以下方式完成

路径类型 固定文件路径 计算出的固定文件路径
相对路径 `"dummy.yml"` `contextBasePath/dummy.yml`, 示例: `%paths.base%/tests/Features/fixtures/ORM/dummy.yml`
@Bundle 路径 `"@AppBundle/DataFixtures/ORM/dummy.yml"` `src/AppBundle/DataFixtures/ORM/dummy.yml` (示例)
绝对路径 `/dummy.yml` 未改变
绝对目录路径 `/tests/Features/fixtures/ORM/` `/tests/Features/fixtures/ORM/*`
@Bundle `@AppBundle` `src/AppBundle/DataFixtures/ORM/*`

路径也可以是目录。

致谢

此库由 Théo FIDRY 开发。

许可证

license