oprudkyi/codeception-events-scripting

Codeception 扩展,用于在 codeception 事件上自动运行 shell 脚本

v3.0.0 2023-05-25 08:01 UTC

This package is auto-updated.

Last update: 2024-09-25 11:03:27 UTC


README

oprudkyi/codeception-events-scripting 这是一个为 Codeception 事件自动运行 shell 脚本的 Codeception 扩展。

Latest Stable Version Total Downloads License Build Status

关于

在 Codeception 的事件上运行 shell 脚本 - 在测试/测试套件之前/之后(如数据库种植、停止运行额外软件等)。受 Phantoman 扩展的启发,但允许以更通用的方式运行任何内容。

最低要求

  • Codeception 2.1.0
  • PHP 5.5

安装

该项目可以通过 Composer 安装。要获取最新版本,只需将以下行添加到您的 composer.json 文件中的 require 块:

{
    "require-dev": {
            "oprudkyi/codeception-events-scripting": "*"
    }

}

然后您需要运行 composer installcomposer update 下载软件包并更新自动加载器。

或者运行以下命令

    composer require oprudkyi/codeception-events-scripting --dev

配置

在 codeception.yml 中启用扩展并编写命令。支持以下事件

  • BeforeAll - 在每次 "codecept run" 测试之前运行
  • AfterAll - 在所有测试之后运行
  • BeforeSuite - 在每个套件之前运行(使用 'suites' 数组仅运行所选套件)
  • AfterSuite - 在每个套件之后运行(使用 'suites' 数组仅运行所选套件)

支持以下属性

  • command - 要运行的命令行(对于单行命令可以直接编写命令)
  • description - 在命令之前输出
  • params - 命令的附加参数
  • ignoreErrors - 如果命令失败则不会中断测试(失败或 retval != 0)
  • suites - 单个名称或套件数组的名称,为运行命令而运行(应用于基本名称,如 'acceptance' 以及长名称 'acceptance (phantom, firefox)')
  • environments - 单个名称或环境数组的名称
  • platforms - 单个名称或平台数组的名称(使用 PHP_OS 常量,即 PHP 被构建的平台,有关详细信息请参阅 此处
extensions:
    enabled:
        - Codeception\Extension\EventsScripting
    config:
        Codeception\Extension\EventsScripting:
            BeforeAll:
                - command: echo "Before All"
                - command: echo "Before All with Description"
                  description: Description of command
                - echo "Before All single line"
                - command: echo 
                  params: "Before All Params"
                  description: Before All with Params
                - command: "false"
                  description: BeforeAll. fail on run but ignore errors
                  ignoreErrors: true
            AfterAll:
                - command: echo "After All"
                - command: uname
                  description: Platform *nx-like
                  platforms: [darwin, linux, bsd, unix]
                - command: ver
                  description: Platform Windows
                  platforms: windows
            BeforeSuite:
                - command: echo "Before acceptance suite"
                  suites: ['acceptance']
                - command: echo "Before any suite"
                - command: echo "Before acceptance suite, phantom environment"
                  suites: ['acceptance']
                  environments: phantom
                - command: echo "Before acceptance suite, phantom,chrome environments"
                  suites: ['acceptance']
                  environments: ['phantom', 'chrome']
            AfterSuite:
                - command: echo "After acceptance suite"
                  suites: 'acceptance'
                - command: echo "After any suite"

实际示例(启动/停止 mailcatcher 和种植数据库)

        Codeception\Extension\EventsScripting:
          BeforeAll:
              - command: ./artisan db:seed-test --env=testing
                description: Reset db and seed
          BeforeSuite:
              - command: GEM_HOME=vendor/ruby vendor/ruby/bin/mailcatcher --ip 127.0.0.1 --smtp-port 11031 --http-port 11091
                suites: 'acceptance' 
                description: Start mailcatcher
          AfterSuite:
              - command: curl -s -X DELETE http://127.0.0.1:11091
                suites: 'acceptance' 
                description: Stop mailcatcher
                ignoreErrors: true

测试

cd sample
composer install -n --prefer-source
cd ../test
composer install -n --prefer-source
./vendor/bin/codecept run

贡献

此软件包目前正在开发中,但已准备好投入生产。请随时评论、贡献和帮助。我很乐意得到一些帮助来交付测试。

许可证

Codeception 的事件脚本根据 MIT 许可证(MIT) 许可。