定制 codeception/robo-paracept 二次开发

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

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

codeception/robo-paracept

Composer 安装命令:

composer require codeception/robo-paracept

包简介

Codeception Parallel Execution Tasks via Robo Task Runner

README 文档

README

PHP Composer Latest Stable Version Total Downloads License

Robo tasks for Codeception tests parallel execution. Requires Robo Task Runner

Install via Composer

composer require codeception/robo-paracept --dev

Include into your RoboFile

<?php

require_once 'vendor/autoload.php';
require_once 'vendor/codeception/codeception/autoload.php';

class RoboFile extends \Robo\Tasks
{
    use Codeception\Task\Merger\ReportMerger;
    use Codeception\Task\Splitter\TestsSplitterTrait;
}

Idea

Parallel execution of Codeception tests can be implemented in different ways. Depending on a project the actual needs can be different. So we prepared a set of predefined Robo tasks that can be combined and reconfigured to fit your needs.

Tasks

SplitTestsByGroups

Load tests from a folder and distributes them between groups.

$result = $this->taskSplitTestsByGroups(5)
    ->testsFrom('tests/acceptance')
    ->projectRoot('.')
    ->groupsTo('tests/_data/group_')
    ->run();

// task returns a result which contains information about processed data:
// optionally check result data   
if ($result->wasSuccessful()) {
    $groups = $result['groups'];
    $tests = $result['tests'];
    $filenames = $result['files'];
}

This command loads Codeception into memory, loads and parses tests to organize them between group. If you want just split test file and not actual tests (and not load tests into memory) use taskSplitTestFilesByGroups:

SplitTestFilesByGroups

To split tests by suites (files) without loading them into memory use taskSplitTestFilesByGroups method:

$result = $this->taskSplitTestFilesByGroups(5)
   ->testsFrom('tests')
   ->groupsTo('tests/_data/paratest_')
   ->run();

// optionally check result data
if ($result->wasSuccessful()) {
    $filenames = $result['files'];
}   

SplitTestsByTime

Enable extension for collect execution time of you use taskSplitTestsByTime

extensions:
    enabled:
        - Codeception\Task\Extension\TimeReporter

Load tests from a folder and distributes them between groups by execution time.

$result = $this->taskSplitTestsByTime(5)
    ->testsFrom('tests/acceptance')
    ->projectRoot('.')
    ->groupsTo('tests/_data/group_')
    ->run();

// optionally check result data
if ($result->wasSuccessful()) {
    $filenames = $result['files'];
}

this command need run all tests with Codeception\Task\TimeReporter for collect execution time. If you want just split tests between group (and not execute its) you can use SplitTestsByGroups. Please be aware: This task will not consider any 'depends' annotation!

SplitFailedTests

Enable extension for collect failed tests if you use taskSplitFailedTests
The extension saves the report files into \Codeception\Configuration::outputDir()

extensions:
    enabled:
        - Codeception\Task\Extension\FailedTestsReporter

Merge the created report files from the FailedTestsReporter into single file

$this->taskMergeFailedTestsReports()
    ->fromPathWithPattern(\Codeception\Configuration::outputDir(), '/failedTests_\w+\.txt$/')
    ->into(\Codeception\Configuration::outputDir() . 'failedTests.txt') // absolute path with Filename
    ->run();

Load the failed Tests from a reportfile into the groups:

$result = $this
    ->taskSplitFailedTests(5)
    ->setReportPath(\Codeception\Configuration::outputDir() . 'failedTests.txt') // absoulute Path to Reportfile
    ->groupsTo(\Codeception\Configuration::outputDir() . 'group_')
    ->run();

// optionally check result data
if ($result->wasSuccessful()) {
    $filenames = $result['files'];
} 

MergeXmlReports

Mergex several XML reports:

$this->taskMergeXmlReports()
    ->from('tests/result/result1.xml')
    ->from('tests/result/result2.xml')
    ->into('tests/result/merged.xml')
    ->run();

MergeHtmlReports

Mergex several HTML reports:

$this->taskMergeHtmlReports()
    ->from('tests/result/result1.html')
    ->from('tests/result/result2.html')
    ->into('tests/result/merged.html')
    ->run();

Filters

You can use a custom filter to select the necessary tests.

Two filters already included: DefaultFilter, GroupFilter

  • DefaultFilter is enabled by default, takes all tests.
  • GroupFilter (Can only be used by taskSplitTestsByGroups), allows you to filter the loaded tests by the given groups. You have the possibility to declare groups which you want to include or exclude. If you declare foo and bar as included, only tests with this both group annotations will be matched. The same thing is happend when you add excluded groups. If you combine the included and excluded group the only tests which have exactly the correct group annotations for the included items and none of the excluded items.

You can add as many filters as you want. The FIFO (First In - First Out) principle applies. The next filter will only get the result of the filter before.

Usage

For example, you want all tests which have in the doc comment the groups 'foo' AND 'bar' but not 'baz' then you can do it like this:

$filter = new GroupFilter();
$filter
    ->groupIncluded('foo')
    ->groupIncluded('bar')
    ->groupExcluded('baz');

$this->taskSplitTestsByGroups(5)
   ->testsFrom('tests')
   ->groupsTo('tests/_data/paratest_')
   ->addFilter($filter)
   ->run();

Now create your own filter class:

<?php

declare(strict_types=1);

namespace ...;

use Codeception\Task\Filter\DefaultFilter;

class CustomFilter extends DefaultFilter {

}

The TestFileSplitterTask.php pushes an array of SplFileInfo Objects to the filter.
The TestsSplitterTask.php pushes an array of SelfDescribing Objects to the filter.

Configuration

Load Codeception config file to specify the path to Codeception before split* tasks:

\Codeception\Configuration::config('tests/codeception.yml');

Contributing

Thank you for contributing to codeception/robo-paracept!

  1. Fork this project
  2. install all deps
  3. create a branch from master
  4. make your changes
  5. extend or create tests for your changes
  6. run composer test (This will execute lint, codestyle and unit tests sequential)
  7. open a Merge Request

Coding Standard

Please note that this project follows the PSR-12 Coding Standard. You can check your coding style with:

composer codestyle

Unit Tests

All changes which you will done must pass the unit tests. If you change some logic or you add some new methods please be fair and write a test.

composer unit

License MIT

codeception/robo-paracept 适用场景与选型建议

codeception/robo-paracept 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.68M 次下载、GitHub Stars 达 57, 最近一次更新时间为 2014 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 codeception/robo-paracept 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 3.68M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 58
  • 点击次数: 26
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 57
  • Watchers: 11
  • Forks: 67
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-30