provision-ops / yaml-tests
Plugin to run commands from a YML file and pass to GitHub commit status API.
Installs: 5 616
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 19
Type:composer-plugin
Requires
- composer-plugin-api: ^1.1
- ext-json: *
- knplabs/github-api: ~2.11
- php-http/guzzle6-adapter: ^1.1
- provision-ops/power-process: 1.4.0-rc2
- teqneers/php-stream-wrapper-for-git: ^2.0
- vlucas/phpdotenv: ~2
Requires (Dev)
- dev-master
- 1.13.1
- 1.13.0
- v1.12.0
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.0
- 1.8.1
- 1.8.0
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/vlucas/phpdotenv-4.2.0
- dev-dependabot/composer/knplabs/github-api-2.19.0
- dev-dependabot/composer/squizlabs/php_codesniffer-3.5.8
- dev-github-actions
- dev-test-github-comment
- dev-ansi-remover
- dev-github-comments
- dev-update-dependencies
- dev-composer-update-383f1886ebc58331dd1120093aef9191
- dev-groups
This package is auto-updated.
Last update: 2024-10-29 05:46:52 UTC
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
cd my-composer-project
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:
-
Use the
--github-token
command line option. Don't use this in CI, or you might expose your GitHub token in logs. -
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.
-
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:
And you will get a nice summary at the end like this:
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
.