theofidry/alice-fixtures-extension

此包已被弃用,不再维护。作者建议使用theofidry/alice-bundle-extension包。

HautelookAliceBundle的加载 fixtures 文件的扩展。

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

This package is auto-updated.

Last update: 2022-02-01 12:50:32 UTC


README

一个Behat 扩展,用于加载HautelookAliceBundle fixtures。

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

默认 fixtures basePath 分别位于

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

基本用法

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

# features/fixtures/ORM/dummy.yml

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

然后,使用以下步骤简单地加载您的 fixtures

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 |

加载 fixture 参数

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

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 |

加载 fixture 文件可以这样做

路径类型 Fixtures 文件路径 计算出的 fixtures 文件路径
相对路径 `"dummy.yml"` `contextBasePath/dummy.yml`, 例如:`%paths.base%/tests/Features/fixtures/ORM/dummy.yml`
`@Bundle path` `"@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