wp-cli/wp-cli-tests
WP-CLI testing framework that bundles shared Behat, PHPUnit, PHP_CodeSniffer, and PHPStan tooling for WP-CLI commands and packages. Add it as a dev dependency to get ready-made test scripts, Behat feature contexts, and linting configs out of the box.
behat-rerun and --stop-on-failure modes shorten the feedback loop, which supports a faster release cadence.WP_VERSION (including latest, trunk, and pinned X.Y) and WP_CLI_TEST_CORE_ZIP let us decide, and then prove, which WordPress versions we support — including pre-release core builds. That turns "we support 6.x" from a claim into a test matrix, which is a pricing and support-contract input for hosting or agency offerings.lint, lint-gherkin, phpcs, phpstan, phpunit, behat) are individual, invokable gates. That lets us decide deliberately which gates are blocking on merge versus advisory, rather than inheriting an all-or-nothing pipeline.WP_CLI_CS plus feature-file scanning means code style and static analysis extend to the PHP embedded in Gherkin fixtures — a gap most teams never close, and a recurring source of broken example code in docs.NO_COLOR and WP_CLI_TEST_QUIET exist specifically so output can be read back by tooling and coding agents, and the repo ships AGENTS.md guidance. That supports a decision to let agents run the narrowest relevant check (composer phpcs -- <file>, composer behat -- features/<name>.feature:<line>) rather than the full suite.composer test installs WordPress from scratch per scenario and takes tens of minutes, needing jq, a MySQL/MariaDB client, and network access. That is a concrete input to CI budget: full suite on pull requests vs. on merge, with narrow checks during development.Adopt when most of the following hold:
Given a WP install, Given these installed and active plugins:, When I run \wp ...``, Then STDOUT should be JSON containing:, exit-code assertions, table/CSV/YAML assertions, and HTTP mocking.jq, and Node.js 20+ for the Gherkin linter.WP_CLI\Tests\TestCase base class and the standard composer script names — over inventing our own.Look elsewhere when:
wp-env or wp-browser/Codeception cover more surface; this package is narrowly about commands and their I/O.lint-gherkin reports "skipping" rather than failing when npx is unavailable, which means a green build may hide a gate that never ran.Adoption effort is genuinely small on the code side — composer require --dev, a scripts block, an optional behat.yml and phpcs.xml.dist, and one composer prepare-tests run. The real cost is CI plumbing and the wall-clock time of the functional suite, not integration.
Two caveats to weigh honestly: the reported 0 dependents almost certainly undercounts, because this is consumed as a dev dependency and therefore largely invisible to dependency graphs — the WP-CLI ecosystem does rely on it. Conversely, 42 stars and a small contributor base is a real concentration risk; mitigate by treating it as a versioned dev dependency we can fork if needed (MIT permits it), and by not letting its scripts become the only place our quality standards are defined.
For executives — one paragraph: We can add proper automated testing to our WordPress command-line tooling at effectively zero licence cost, using the same MIT-licensed test framework the official WP-CLI project uses internally. It replaces custom test scaffolding we would otherwise build and maintain, and it lets us state and verify which WordPress versions we support — including pre-release versions — which is directly relevant to support commitments and to any hosting or agency offering we price. The cost is a small integration effort and some CI time, not engineering headcount.
For engineering — the practical case: It ships the hard parts we would otherwise rewrite: Behat contexts that install and configure WordPress (single site, multisite subdirectory/subdomain, Composer-based installs, custom wp-content), fixtures and file assertions, STDOUT/STDERR format assertions (JSON, CSV, YAML, tables), HTTP mocking, PHAR build/download steps, and a WP_CLI\Tests\TestCase base class. It also enforces WP_CLI_CS and PHPStan over the PHP blocks embedded in feature files — a category of code that normally escapes review entirely. Everything is a discrete Composer script, so we choose our blocking gates. NO_COLOR and WP_CLI_TEST_QUIET make output machine-readable for CI logs and coding agents, and behat-rerun / --stop-on-failure / tag and line-number filtering keep the inner loop fast.
For engineering leadership — the risk framing: Pin the version and treat it as forkable. Budget for the CI environment it assumes (MySQL/MariaDB client with a prepared test database, jq, network access, Node 20+ if we want Gherkin linting), and expect the full suite to run in tens of minutes — run narrow checks per change and the full suite before merge. Note explicitly that a green composer test is not the same as a green CI, and that the Gherkin linter skips rather than fails when npx is missing; we should assert it actually ran.
The one-line version: Free, ecosystem-standard functional testing for our WordPress CLI tooling — adopt it to spend our engineering time on commands rather than on test plumbing.
How can I help you explore Laravel packages today?