provision-ops/yaml-tests 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

provision-ops/yaml-tests

Composer 安装命令:

composer require provision-ops/yaml-tests

包简介

Plugin to run commands from a YML file and pass to GitHub commit status API.

README 文档

README

Yaml Tests is a simple composer plugin tthat make it as simple as possible to define and run a set of tests.

The plugin provides a composer command that simply reads a YML file and runs the lines as a process.

The output is rendered in a way to be easier to read, and proper exit code returns if a single process fails.

It can be installed "locally" (included in your composer.json file) or "globally" (installed into the global "composer" command.

Installation

Keeping yaml-tests in your composer.json (local install) is the most stable way to operate, since the version is pinned.

Local Install

  1. cd my-composer-project
  2. composer require provision-ops/yaml-tests

Global Install

composer global require provision-ops/yaml-tests

To confirm the command is installed, ask for help:

composer yaml-tests --help

GitHub Integration

If you pass yaml-tests a GitHub Token, it will send the test results as "commit status" indicators.

There are 3 ways to pass the GitHub Token to YamlTests:

  1. Use the --github-token command line option. Don't use this in CI, or you might expose your GitHub token in logs.

  2. Set a GITHUB_TOKEN environment variable. This is pretty simple in Docker, but can be a challenge if your tests get run in different environments.

  3. Recommended: Create a .env file in your repo, or in your user's home directory:

    GITHUB_TOKEN=abcdefg
    

    There is a .env.example file in this directory you can use as an example.

Writing Tests

Create tests.yml file

By default the composer yaml-tests command looks for a tests.yml file in the project root. You can also pass a path using the --tests-file option.

The tests.yml file is read as a simple collection of commands. The key can be any string, as long as it is unique in the test suite.

test/dir: pwd
test/environment: env

You can also include commands in a list:

lint:
  - find src -name '*.php' -print0 | xargs -0 -n1 php -l
  - find web/modules/custom -name '*.php' -print0 | xargs -0 -n1 php -l
  - find tests/src -name '*.php' -print0 | xargs -0 -n1 php -l

You can include a description for each test like:

debug: 
  command: env
  description: Current Environment

Commands in tests.yml

Yaml Tests work like Composer Scripts: If your project has the config.bin-dir set in composer.json, Composer will automatically add that directory to the PATH when scripts or other commands are run.

For example, you can include PHPUnit and call it without specifying the full path in composer scripts or tests.yml

composer.json:

{
    "config": {
        "bin-dir": "bin/"
    },
    "require": {
        "provision-ops/yaml-tests": "^1.1",
        "phpunit/phpunit": "^8.1"
    },
    "scripts": {
        "test": [
            "which phpunit",
            "phpunit --version"
        ]
    }
}

Having the scripts.test section in composer.json creates a composer command called composer test.

tests.yml:

test/debug: 
  - which phpunit
  - phpunit --version

If you want to only maintain one set of scripts, you can reference composer scripts in tests.yml:

tests.yml:

test/debug: composer test 

Running tests

Once the tests.yml file is in place, and the composer yaml-tests command is available, you can trigger test runs.

Dry Runs vs Normal

This plugin was also designed to pass these tests as "Commit Statuses" on GitHub. This allows us to tag the results to the specific commit, pass or fail.

If the environment variable GITHUB_TOKEN or the command line option --github-token is NOT set, the --dry-run option will be forced.

Use the --dry-run option if you have a token set but do not want to post test results to GitHub.

Run composer yaml-tests or, just like all composer commands, you can use shortcuts like compose y.

composer yaml-tests

The output will look something like this:

Test Run

And you will get a nice summary at the end like this:

Test Run

Yaml-Tests executable

There is now a "bin" for yaml-tests, allowing the command to be run by itself.

If you require provision-ops/yaml-tests, you will see a link to yaml-tests in your bin-dir.

provision-ops/yaml-tests 适用场景与选型建议

provision-ops/yaml-tests 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.26k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 provision-ops/yaml-tests 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 6.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-22