定制 dmarynicz/behat-parallel-extension 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dmarynicz/behat-parallel-extension

Composer 安装命令:

composer require dmarynicz/behat-parallel-extension

包简介

Parallel extension for Behat

README 文档

README

Packagist Version License: MIT PHP Tests

Intro

This extension is for an executing behat 3.x tests in parallel mode.

Behat Parallel Runner

If you Properly integrate your app with this extension then it can be dramatically speed up your behat tests!

Features

  • Displays nice progress bar :).
  • Extension can cancel your tests when you hit CTRL+C.
  • When you have failed tests in Parallel scenario mode then can you rerun this test with Behat option --rerun.
  • For each worker you can set environment variables.
  • You can group scenarios or features into a single job to improve test execution time by using the same kernel bootstrapped once.

Main modes

Behat Parallel Extension can work in two main modes:

  • Parallel scenario witch can be enabled by option --parallel or -l.
  • Parallel feature to enable this you need use behat option --parallel-feature.
  • Parallel chunk size to group multiple scenarios or features into a single job, use the --parallel-chunk-size option (default is 1). Only available with Behat >= 3.23

Requirements

PHP compatibility

This Behat extension requires php 5.6 or higher. The main reason for choosing php 5.6 is to be able to share this tool with more programmers :).

Installing Behat Parallel Extension

The most convenient way to install Behat Parallel Extension is by using Composer:

For more information about installing Composer please follow the documentation: https://getcomposer.org/download/

Install

composer  require --dev dmarynicz/behat-parallel-extension

Configuration

You can then activate and configure the extension in your behat.yml or behat.yml.dist. In the array environments you can set you environment vars for each worker. From this environments array depends on how much maximum you can run Workers. If you do note set environments array then you can run an unlimited amount of Workers. If the environmental array is defined, the maximum number of workers is the size of this array.

Example for maximum 4 Workers:

default:
    # ...
    extensions:
        DMarynicz\BehatParallelExtension\Extension:
          environments:
            -
              ANY_YOUR_ENV_VARIABLE: with any value
              DATABASE_URL:        mysql://db_user:db_password@127.0.0.1:3306/db_name_00?serverVersion=5.7
            -
              ANY_YOUR_ENV_VARIABLE: with any value
              DATABASE_URL:        mysql://db_user:db_password@127.0.0.1:3306/db_name_01?serverVersion=5.7
            -
              ANY_YOUR_ENV_VARIABLE: with any value
              DATABASE_URL:        mysql://db_user:db_password@127.0.0.1:3306/db_name_02?serverVersion=5.7
            -
              ANY_YOUR_ENV_VARIABLE: with any value
              DATABASE_URL:        mysql://db_user:db_password@127.0.0.1:3306/db_name_03?serverVersion=5.7

Example for maximum an unlimited amount of Workers:

default:
    # ...
    extensions:
        DMarynicz\BehatParallelExtension\Extension: ~

Integration with SymfonyExtension and Symfony

To integrate this extension with SymfonyExtension and MinkExtension you need install by Composer command packages

composer require --dev \
    friends-of-behat/mink \
    friends-of-behat/mink-extension \
    friends-of-behat/mink-browserkit-driver \
    friends-of-behat/symfony-extension

Configure the extension in your behat.yml or behat.yml.dist as in this example:

default:
  suites:
    default:
      contexts:
        # Your contexts...
  extensions:
    Behat\MinkExtension:
      sessions:
        symfony:
          symfony: ~
    FriendsOfBehat\SymfonyExtension:
      # for symfony 5.3+ with symfony/runtime installed by composer command
      bootstrap: tests/bootstrap.php
      # for symfony versions older than 5.3
      #bootstrap: config/bootstrap.php

    DMarynicz\BehatParallelExtension\Extension:
      environments:
        - DATABASE_URL: "sqlite:///%%kernel.project_dir%%/var/data_test1.db"
          # doc for APP_CACHE_DIR https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-cache-directory
          APP_CACHE_DIR: "var/cache1"
          # SYMFONY_DOTENV_VARS does not have symfony's docs but without this tests will ignore env vars like DATABASE_URL, APP_CACHE_DIR and tests will not work
          SYMFONY_DOTENV_VARS:
        - DATABASE_URL: "sqlite:///%%kernel.project_dir%%/var/data_test2.db"
          APP_CACHE_DIR: "var/cache2"
          SYMFONY_DOTENV_VARS:
        - DATABASE_URL: "sqlite:///%%kernel.project_dir%%/var/data_test3.db"
          APP_CACHE_DIR: "var/cache3"
          SYMFONY_DOTENV_VARS:
        - DATABASE_URL: "sqlite:///%%kernel.project_dir%%/var/data_test4.db"
          APP_CACHE_DIR: "var/cache4"
          SYMFONY_DOTENV_VARS:

In tests/bootstrap.php for Symfony 5.3+ you need to have

<?php

use Symfony\Component\Dotenv\Dotenv;

require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');

Full example is available at https://github.com/Daniel-Marynicz/BehatParallelExtension-IntegrationWithSymfony-Example

Usage

Use --parallel or -l option for start in parallel scenario mode. Or use --parallel-feature to start in parallel feature mode. Optionally you can to specify number of concurrent workers in these modes. Examples with enabled option --colors:

$ vendor/bin/behat -l 8 --colors
Starting parallel tests with 8 workers
 Feature: Parallel
  Scenario: Test behat tests with failed result
 3/3 [============================] 100% 12 secs/12 secs
$ vendor/bin/behat --parallel-feature 8 --colors
Starting parallel tests with 8 workers
 Feature: Parallel
 
 3/3 [============================] 100% 12 secs/12 secs
$ vendor/bin/behat --parallel 8 --colors --parallel-chunk-size 2
Starting parallel tests with 8 workers
 Feature: Parallel, Any other feature
  Scenario: Test behat tests with failed result, Any other scenario
 3/3 [============================] 100% 12 secs/12 secs

Test with the oldest supported PHP version and oldest vendors

With docker, without Dockerfile:

# Create the docker container
docker run --rm -d -v $(pwd):/app -w /app --name behat-parallel-old-php php:7.4-cli bash -c "tail -f /dev/null"
# Install deps
docker exec -ti behat-parallel-old-php bash -c "apt-get update && apt-get install -y libzip-dev && docker-php-ext-install zip"
# Install composer for the current user
docker exec -ti -u $(id -u):$(id -g) -e HOME=/tmp behat-parallel-old-php bash -c "curl -s https://getcomposer.org/installer | php -- --install-dir=/tmp; php /tmp/composer.phar update --prefer-lowest --prefer-dist;"
# Run tests
docker exec -ti -u $(id -u):$(id -g) behat-parallel-old-php php /tmp/composer.phar phpunit
docker exec -ti -u $(id -u):$(id -g) behat-parallel-old-php php /tmp/composer.phar behat
# Stop and remove the docker container
docker kill behat-parallel-old-php

Tools and Coding standards

The extension uses the following coding standards and quality tools:

Doctrine Coding Standard

The Doctrine Coding Standard with some exceptions for php 5.6 compatibility. The Doctrine Coding Standard is a set of rules for PHP_CodeSniffer. It is based on PSR-1 and PSR-12 , with some noticeable exceptions/differences/extensions.

For more information about Doctrine Coding Standard please follow the documentation:

https://www.doctrine-project.org/projects/doctrine-coding-standard/en/latest/reference/index.html#introduction

PHPStan

PHPStan A php framework for auto testing your business expectations. PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line.

PHPUnit

PHPUnit The PHP Testing Framework with tests in directory tests

Behat

You can find Behat tests in directory features and fixtures in tests/fixtures and some classes for behat tests in directory tests/Behat.

dmarynicz/behat-parallel-extension 适用场景与选型建议

dmarynicz/behat-parallel-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 630.69k 次下载、GitHub Stars 达 28, 最近一次更新时间为 2020 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Symfony2」 「BDD」 「Behat」 「Context」 「extension」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dmarynicz/behat-parallel-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dmarynicz/behat-parallel-extension 我们能提供哪些服务?
定制开发 / 二次开发

基于 dmarynicz/behat-parallel-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 630.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 28
  • 点击次数: 19
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 28
  • Watchers: 2
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-09