drupol / phingbehattask

Phing 的 Behat 任务。

1.2.1 2023-02-17 07:48 UTC

This package is auto-updated.

Last update: 2024-09-17 11:14:54 UTC


README

Build Status

一个针对 Phing 的 Behat 任务。此任务使 Behat 命令能够在 Phing 构建脚本中使用。

Phing 为 PHP 项目提供了常用任务工具(phplint、jslint、VCS 检出、文件复制或合并、打包、上传等)。在持续集成服务器(如 JenkinsTravisContinuous PHP)中构建和测试 Drupal 项目时,Behat 与 Phing 的集成特别有用。

安装

必须通过 Composer 进行安装

  composer require drupol/phingbehattask

或通过编辑您的 composer.json 文件,在正确的部分添加

{
  "require": {
    "drupol/phingbehattask": "dev-master"
  }
}

使用方法

Behat 任务

要使用构建文件中的 Behat 任务,它必须对 Phing 可用,以便构建文件解析器知道相关联的 XML 元素及其参数。

这是通过向您的构建文件添加一个 <taskdef> 任务来完成的

  <taskdef name="behat" classname="\Phing\Behat\Task" />

或通过导入 import.xml 文件

  <import file="vendor/drupol/phingbehattask/import.xml"/>

导入后,您就可以使用了

  <behat bin="${project.basedir}/vendor/behat/behat/bin/behat" haltonerror="yes" colors="yes" verbose="${behat.options.verbosity}">
    <option name="config=">${project.basedir}/tests/behat.yml</option> 
  </behat>

有关 <taskdef> 任务的更多信息,请参阅 Phing 文档

由于 Phing Behat 任务扩展了 Phing ExecTask,因此您可以使用该命令的所有选项。

有关完整选项列表,请参阅 ExecTask 文档

Behat 负载均衡任务

Behat 负载均衡任务将您的功能文件拆分成任意数量的 Behat 配置文件。

要使用构建文件中的 Behat 负载均衡任务,它必须对 Phing 可用,以便构建文件解析器知道相关联的 XML 元素及其参数。

这是通过向您的构建文件添加一个 <taskdef> 任务来完成的

  <taskdef name="behat:balancer" classname="\Phing\Behat\Balancer" />

或通过导入 import.xml 文件

  <import file="vendor/drupol/phingbehattask/import.xml"/>

导入后,您可以按照以下方式使用它

  <behat:balancer
    containers="5"
    root="/path/to/your/behat/features/directory"
    destination="/path/to/destination/directory"
    import="/path/to/base/behat/configuration/behat.yml"
  />

以下属性具有以下含义

  • containers:功能文件将被拆分为的 Behat 配置文件数量。
  • root:您的 Behat /features 目录的路径。
  • destination:新 behat 文件将被生成的目标目录。
  • import:要导入到每个生成文件中的主 Behat 配置文件。

然后您可以根据环境配置您的持续集成,每次运行一个 behat 文件。

过滤

当使用多个配置文件时,Behat 负载均衡器还允许根据标签进行过滤。

过滤与 behat 过滤 [http://behat.org/en/latest/user_guide/configuration/suites.html#suite-filters]

以下示例将首先使用标签作为过滤器将功能过滤到特定配置文件中

  • 默认:不包含 @wip、@profile 和 @login,并且必须包含 @theme 将仅包括并平衡。
  • 二级配置文件:不包含 @secondary_profile 和 @api,并且必须包含 @secondary_theme 或文本 'As an administrator' 将仅包括并平衡。过滤器基于 behat 的过滤器,因此也会匹配包含标记的功能。
  <behat:balancer
    containers="5"
    root="/path/to/your/behat/features/directory"
    destination="/path/to/destination/directory"
    import="/path/to/base/behat/configuration/behat.yml"
  >
    <filters profile="default">
        <tags><![CDATA[ ~@wip&&~@profile&&~@login&&@theme ]]></tags>
    </filters>
    <filters profile="secondary_profile">
        <tags><![CDATA[ ~@secondary_profile&&~@api&&@secondary_theme ]]></tags>
        <role>administrator</role>
    </filters>
  </behat:balancer>

平衡文件将按照以下格式生成文件:behat.{profile}.{part}.yml,并产生输出

imports:
  - {behat_configuration_file}
{profile}:
  suites:
    default:
      paths:
        - {feature}
        - {feature}

如果没有过滤器,为了向后兼容,文件名将保持为behat.{part}.yml