Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0aed733
Turn AGENTS.md rules into checks
claude Dec 4, 2026
7209d1d
Pass the runner command to proc_open() as a string for PHP < 7.4
claude Dec 4, 2026
bd4a557
Detect Antigravity through ANTIGRAVITY_AGENT as well
claude Dec 4, 2026
aba6fd5
Report undefined Behat steps with the closest existing ones
claude Dec 4, 2026
94fd837
Match undefined steps the way Behat does
claude Dec 4, 2026
f77fe79
Test which feature files and lines the step check reads
claude Dec 4, 2026
3e4ea73
Expect the directory separator Windows uses for found feature files
claude Dec 4, 2026
cef368b
Align the array arrows in the feature files test
claude Dec 4, 2026
33bc5e1
Select the scenarios to check with Behat's own parser and filters
claude Dec 4, 2026
698bb19
Check the steps of rules, and a rule's background only for its scenarios
claude Dec 4, 2026
725cec1
Skip the step check when the Behat configuration may filter scenarios
claude Dec 4, 2026
3545042
Fill in outline examples in the steps of a rule's background
claude Dec 4, 2026
4d09b21
Run Behat anyway when the step check itself fails
claude Dec 4, 2026
8208ee6
Expect Behat 3's legacy reading of a rule in the outline test
claude Dec 4, 2026
9e7cc96
Follow BEHAT_FEATURES_FOLDER, and let workers and listing failures pass
claude Dec 4, 2026
29dbbd4
Report only steps that are undefined in every reading of the file
claude Dec 4, 2026
3259cd1
Match placeholders like Behat, and keep every selected outline subset
claude Dec 4, 2026
4b3d28d
Describe the placeholder token as it now is
claude Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bin/run-behat-tests
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/bash

# AI coding agents pay for every byte of a report they read back, so they get
# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET
# to an empty string keeps the full report.
if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then
[ -n "${NO_COLOR+set}" ] || export NO_COLOR=1
[ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1
fi

# Run the Behat tests only if a Behat config file is found.
if [ ! -f "behat.yml" ] && [ ! -f "behat.php" ] && [ ! -f "behat.dist.php" ]; then
echo 'Did not detect "behat.yml" file, skipping Behat tests.'
Expand Down Expand Up @@ -317,6 +325,27 @@ fi
# Generate the tags to apply environment-specific filters.
BEHAT_TAGS=$(php "$WP_CLI_TESTS_ROOT"/utils/behat-tags.php)

# Report steps that no definition matches before any scenario is set up, each
# with the closest existing steps. Behat would only report them once a scenario
# reached them, and suggest snippets for new step definitions instead.
CHECK_STEPS=1
for arg in "$@"; do
case "$arg" in
-d*|--definitions|--definitions=*|--rerun|--rerun-only|--init|-h|--help|--story-syntax) CHECK_STEPS="";;
esac
done
# Only a finding stops the run: if the check itself fails, for example because the PHP on the host
# cannot load the project's dependencies, Behat runs as it would without it.
if [ -n "${CHECK_STEPS}" ]; then
CHECK_STEPS_STATUS=0
php "$WP_CLI_TESTS_ROOT"/utils/check-feature-steps.php "$BEHAT_TAGS" "$@" || CHECK_STEPS_STATUS=$?
if [ "${CHECK_STEPS_STATUS}" -eq 1 ]; then
exit 1
elif [ "${CHECK_STEPS_STATUS}" -ne 0 ]; then
echo "Warning: could not check the feature files for undefined steps (exit status ${CHECK_STEPS_STATUS}), running Behat without the check." >&2
fi
fi

BEHAT_EXTRA_ARGS=()
if [[ "${WP_CLI_TEST_COVERAGE}" == "true" ]] && vendor/bin/behat --help 2>/dev/null | grep -q 'xdebug'; then
BEHAT_EXTRA_ARGS+=('--xdebug')
Expand Down
8 changes: 8 additions & 0 deletions bin/run-gherkin-lint-tests
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh

# AI coding agents pay for every byte of a report they read back, so they get
# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET
# to an empty string keeps the full report.
if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then
[ -n "${NO_COLOR+set}" ] || export NO_COLOR=1
[ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1
fi

# Run the Gherkin linter only if there are feature files to lint.
if [ ! -d "features" ]
then
Expand Down
8 changes: 8 additions & 0 deletions bin/run-linter-tests
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh

# AI coding agents pay for every byte of a report they read back, so they get
# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET
# to an empty string keeps the full report.
if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then
[ -n "${NO_COLOR+set}" ] || export NO_COLOR=1
[ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1
fi

# Honor the NO_COLOR convention (https://no-color.org/). This has to turn the
# color off explicitly rather than omit the flag, because the tool's own
# detection only asks whether STDOUT is a terminal and knows nothing about
Expand Down
8 changes: 8 additions & 0 deletions bin/run-php-unit-tests
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh

# AI coding agents pay for every byte of a report they read back, so they get
# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET
# to an empty string keeps the full report.
if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then
[ -n "${NO_COLOR+set}" ] || export NO_COLOR=1
[ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1
fi

# Run the unit tests, if they exist
if [ -f "phpunit.xml" ] || [ -f "phpunit.xml.dist" ] || [ -f ".phpunit.xml" ] || [ -f ".phpunit.xml.dist" ]
then
Expand Down
8 changes: 8 additions & 0 deletions bin/run-phpcs-tests
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh

# AI coding agents pay for every byte of a report they read back, so they get
# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET
# to an empty string keeps the full report.
if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then
[ -n "${NO_COLOR+set}" ] || export NO_COLOR=1
[ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1
fi

EXIT_CODE=0

# 1. Run standard PHP code style check if a configuration file exists.
Expand Down
8 changes: 8 additions & 0 deletions bin/run-phpstan-tests
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh

# AI coding agents pay for every byte of a report they read back, so they get
# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET
# to an empty string keeps the full report.
if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then
[ -n "${NO_COLOR+set}" ] || export NO_COLOR=1
[ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1
fi

EXIT_CODE=0

# 1. Run the static analysis only if a configuration file exists.
Expand Down
1 change: 1 addition & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
- phpstan.parser.richParserNodeVisitor
rules:
- WP_CLI\Tests\PHPStan\WPCliAddHookCallbackRule
- WP_CLI\Tests\PHPStan\TestCaseParentRule

parameters:
dynamicConstantNames:
Expand Down
4 changes: 4 additions & 0 deletions src/Context/Support.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ protected function missing_command_hint( $stderr = null ): string {
$stderr = (string) $this->result->stderr;
}

if ( preg_match( "/'([^']+)' is not a registered wp command\./", $stderr, $matches ) ) {
return "\n\nThe WP-CLI command `{$matches[1]}` is not installed. Only the commands of the packages in composer.json (`require` or `require-dev`) can be run in the tests, so add the package that provides it there.";
}

if (
! preg_match( '/\b(?:sh|bash|dash|zsh)(?:: line \d+|: \d+)?: ([A-Za-z0-9_.+-]+): (?:command )?not found/', $stderr, $matches )
&& ! preg_match( "/'([A-Za-z0-9_.+-]+)' is not recognized as an internal or external command/", $stderr, $matches )
Expand Down
53 changes: 53 additions & 0 deletions src/PHPStan/TestCaseParentRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace WP_CLI\Tests\PHPStan;

use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;

use function sprintf;
use function strtolower;

/**
* Reports test classes that extend PHPUnit's TestCase directly.
*
* WP_CLI\Tests\TestCase adds the PHPUnit Polyfills, so the same test runs on
* every PHPUnit version that the supported PHP versions need.
*
* @implements Rule<Class_>
*/
final class TestCaseParentRule implements Rule {

public function getNodeType(): string {
return Class_::class;
}

public function processNode( Node $node, Scope $scope ): array {
if ( null === $node->extends ) {
return [];
}

$parent = $scope->resolveName( $node->extends );

if ( 'phpunit\\framework\\testcase' !== strtolower( $parent ) ) {
return [];
}

return [
RuleErrorBuilder::message(
sprintf(
'Test class %s extends %s directly. Extend WP_CLI\\Tests\\TestCase instead, so the test runs on every supported PHPUnit version.',
null !== $node->name ? $node->name->toString() : 'class@anonymous',
$parent
)
)
->identifier( 'wpcli.testCaseParent' )
->build(),
];
}
}
Loading
Loading