Skip to content

Commit 3e81fbb

Browse files
authored
Merge branch 'main' into try/os
2 parents 7daf3d5 + 79ab345 commit 3e81fbb

File tree

8 files changed

+74
-9
lines changed

8 files changed

+74
-9
lines changed

.github/workflows/copilot-setup-steps.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ jobs:
2121

2222
- name: Check existence of composer.json file
2323
id: check_composer_file
24-
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
25-
with:
26-
files: "composer.json"
24+
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
2725

2826
- name: Set up PHP environment
2927
if: steps.check_composer_file.outputs.files_exists == 'true'
30-
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
28+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
3129
with:
3230
php-version: 'latest'
3331
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -38,7 +36,7 @@ jobs:
3836

3937
- name: Install Composer dependencies & cache dependencies
4038
if: steps.check_composer_file.outputs.files_exists == 'true'
41-
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3
39+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v3
4240
env:
4341
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4442
with:

WP_CLI_CS/ruleset.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@
8484
</rule>
8585

8686

87+
<!--
88+
#############################################################################
89+
USE THE SLEVOMATCODINGSTANDARD RULESET
90+
91+
This checks code for unused `use` statements.
92+
See: https://github.com/slevomat/coding-standard
93+
#############################################################################
94+
-->
95+
96+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
97+
<properties>
98+
<property name="searchAnnotations" value="true"/>
99+
</properties>
100+
<!-- Exclude case-sensitivity check: PHPUnit's @dataProvider annotation uses a
101+
lowercase method name which can cause false positives with the DataProvider
102+
attribute class import (PHPUnit\Framework\Attributes\DataProvider). -->
103+
<exclude name="SlevomatCodingStandard.Namespaces.UnusedUses.MismatchingCaseSensitivity"/>
104+
</rule>
105+
106+
87107
<!--
88108
#############################################################################
89109
SPECIFIC CONFIGURATION FOR SNIFFS

bin/run-behat-tests

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ if [ "${WP_VERSION-latest}" = "latest" ]; then
9494
export WP_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r ".offers[0].current")
9595
fi
9696

97+
# Normalize WP_VERSION=X.Y.0 to X.Y (WordPress uses X.Y for the initial release, not X.Y.0).
98+
# If WP_VERSION=X.Y (major.minor only), resolve to the latest available patch release.
99+
if [[ "${WP_VERSION}" =~ ^([0-9]+\.[0-9]+)\.0$ ]]; then
100+
export WP_VERSION="${BASH_REMATCH[1]}"
101+
elif [[ "${WP_VERSION}" =~ ^[0-9]+\.[0-9]+$ ]]; then
102+
WP_VERSIONS_JSON=$(curl -s https://raw.githubusercontent.com/wp-cli/wp-cli-tests/artifacts/wp-versions.json)
103+
if [ -n "${WP_VERSIONS_JSON}" ]; then
104+
RESOLVED_VERSION=$(echo "${WP_VERSIONS_JSON}" | jq -r --arg prefix "${WP_VERSION}." 'keys | map(select(startswith($prefix))) | sort_by(split(".") | map(tonumber)) | last // empty')
105+
if [ -n "${RESOLVED_VERSION}" ]; then
106+
export WP_VERSION="${RESOLVED_VERSION}"
107+
fi
108+
fi
109+
fi
110+
97111
# To retrieve the WP-CLI tests package root folder, we start with this scripts
98112
# location.
99113
SOURCE="${BASH_SOURCE[0]}"

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"phpstan/phpstan-deprecation-rules": "^1.2 || ^2.0",
2121
"phpstan/phpstan-phpunit": "^1.4 || ^2.0",
2222
"phpstan/phpstan-strict-rules": "^1.6 || ^2.0",
23+
"slevomat/coding-standard": "^7.0 || ^8.0",
2324
"swissspidy/phpstan-no-private": "^0.2.1 || ^1.0",
2425
"szepeviktor/phpstan-wordpress": "^1.3.5 || ^2.0.3",
2526
"wp-cli/config-command": "^1 || ^2",

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ parameters:
1818
- WP_DEBUG
1919
- WP_DEBUG_LOG
2020
- WP_DEBUG_DISPLAY
21-
ignoreErrors:
2221
strictRules:
2322
strictCalls: true

src/Context/Support.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace WP_CLI\Tests\Context;
77

8-
use Behat\Behat\Exception\PendingException;
98
use Exception;
109
use Mustangostang\Spyc;
1110
use SebastianBergmann\Diff\Differ;
@@ -123,6 +122,23 @@ protected function check_string( $output, $expected, $action, $message = false,
123122
$message = $output;
124123
}
125124

125+
$action_message = '';
126+
switch ( $action ) {
127+
case 'be':
128+
$action_message = 'Output does not exactly match expected string:';
129+
break;
130+
case 'contain':
131+
$action_message = 'Output does not contain expected string:';
132+
break;
133+
case 'not contain':
134+
$action_message = 'Output unexpectedly contains string:';
135+
break;
136+
default:
137+
throw new \Behat\Behat\Tester\Exception\PendingException();
138+
}
139+
140+
$message .= "\n\n" . $action_message . "\n" . $expected;
141+
126142
$diff = $this->generate_diff( $expected, rtrim( $output, "\n" ) );
127143
if ( ! empty( $diff ) ) {
128144
$message .= "\n\n" . $diff;

src/Context/WhenStepDefinitions.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,24 @@ public function wpcli_tests_invoke_proc( $proc, $mode ) {
1919
);
2020
$method = $map[ $mode ];
2121

22-
return $proc->$method();
22+
try {
23+
return $proc->$method();
24+
} catch ( \RuntimeException $e ) {
25+
if ( 'run' === $mode ) {
26+
$message = $e->getMessage();
27+
$status = preg_match( '/exit status: (\d+)$/', $message, $matches ) ? $matches[1] : 'unknown';
28+
29+
if ( '0' === $status ) {
30+
$message .= "\n\nThe command unexpectedly produced STDERR output. If you expect a non-zero exit status or STDERR output, use `When I try [...]`. Else, this may be a bug in your code or test.";
31+
} else {
32+
$message .= "\n\nThe command unexpectedly exited with status {$status}. If you expect a non-zero exit status, use `When I try [...]`. Else, this may be a bug in your code or test.";
33+
}
34+
35+
throw new \RuntimeException( $message, $e->getCode(), $e );
36+
}
37+
38+
throw $e;
39+
}
2340
}
2441

2542
/**

src/PHPStan/ParseUrlFunctionDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getTypeFromFunctionCall( FunctionReflection $functionReflection,
8181
$types = [];
8282
foreach ( $urlType->getConstantStrings() as $constantString ) {
8383
try {
84-
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
84+
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
8585
$result = @parse_url( $constantString->getValue(), $componentType->getValue() );
8686
} catch ( \Error $e ) {
8787
$types[] = new ConstantBooleanType( false );

0 commit comments

Comments
 (0)