Skip to content

Commit 8ececcb

Browse files
committed
Merge branch 'main' into try/os
2 parents ef13e97 + 53d9dbd commit 8ececcb

File tree

10 files changed

+208
-83
lines changed

10 files changed

+208
-83
lines changed

.gemini/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"context": {
3+
"fileName": "AGENTS.md"
4+
},
5+
"advanced": {
6+
"bugCommand": {
7+
"urlTemplate": "https://github.com/wp-cli/wp-cli-tests/issues/new?template=1-BUG_REPORT.md&title={title}"
8+
}
9+
}
10+
}

.gemini/settings.json.orig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "contextFileName": "AGENTS.md", "advanced": { "bugCommand": { "urlTemplate": "https://github.com/wp-cli/wp-cli-tests/issues/new?template=1-BUG_REPORT.md&title={title}" } } }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Check Branch Alias
2+
3+
on:
4+
release:
5+
types: [released]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
check-branch-alias:
14+
uses: wp-cli/.github/.github/workflows/reusable-check-branch-alias.yml@main
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "Copilot Setup Steps"
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- .github/workflows/copilot-setup-steps.yml
8+
pull_request:
9+
paths:
10+
- .github/workflows/copilot-setup-steps.yml
11+
12+
jobs:
13+
copilot-setup-steps:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v6
21+
22+
- name: Check existence of composer.json file
23+
id: check_composer_file
24+
uses: andstor/file-existence-action@v3
25+
with:
26+
files: "composer.json"
27+
28+
- name: Set up PHP environment
29+
if: steps.check_composer_file.outputs.files_exists == 'true'
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: 'latest'
33+
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
34+
coverage: 'none'
35+
tools: composer,cs2pr
36+
env:
37+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Install Composer dependencies & cache dependencies
40+
if: steps.check_composer_file.outputs.files_exists == 'true'
41+
uses: ramsey/composer-install@v3
42+
env:
43+
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
44+
with:
45+
# Bust the cache at least once a month - output format: YYYY-MM.
46+
custom-cache-suffix: $(date -u "+%Y-%m")

.github/workflows/issue-triage.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Issue and PR Triage
3+
4+
'on':
5+
issues:
6+
types: [opened]
7+
pull_request_target:
8+
types: [opened]
9+
workflow_dispatch:
10+
inputs:
11+
issue_number:
12+
description: 'Issue/PR number to triage (leave empty to process all)'
13+
required: false
14+
type: string
15+
16+
jobs:
17+
issue-triage:
18+
uses: wp-cli/.github/.github/workflows/reusable-issue-triage.yml@main
19+
with:
20+
issue_number: >-
21+
${{
22+
(github.event_name == 'workflow_dispatch' && inputs.issue_number) ||
23+
(github.event_name == 'pull_request_target' && github.event.pull_request.number) ||
24+
(github.event_name == 'issues' && github.event.issue.number) ||
25+
''
26+
}}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Manage Labels
3+
4+
'on':
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- main
9+
- master
10+
paths:
11+
- 'composer.json'
12+
13+
permissions:
14+
issues: write
15+
contents: read
16+
17+
jobs:
18+
manage-labels:
19+
uses: wp-cli/.github/.github/workflows/reusable-manage-labels.yml@main
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Welcome New Contributors
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
branches:
7+
- main
8+
- master
9+
10+
jobs:
11+
welcome:
12+
uses: wp-cli/.github/.github/workflows/reusable-welcome-new-contributors.yml@main

bin/run-behat-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,4 @@ if [[ "${WP_CLI_TEST_COVERAGE}" == "true" ]] && vendor/bin/behat --help 2>/dev/n
120120
fi
121121

122122
# Run the functional tests.
123-
vendor/bin/behat --format progress "$BEHAT_TAGS" --strict "${BEHAT_EXTRA_ARGS[@]}" "$@"
123+
vendor/bin/behat --snippets-for="WP_CLI\Tests\Context\FeatureContext" --format progress "$BEHAT_TAGS" --strict "${BEHAT_EXTRA_ARGS[@]}" "$@"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"extra": {
4545
"branch-alias": {
46-
"dev-main": "5.0.x-dev"
46+
"dev-main": "5.1.x-dev"
4747
},
4848
"phpstan": {
4949
"includes": [

src/Context/FeatureContext.php

Lines changed: 78 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace WP_CLI\Tests\Context;
44

5-
use Behat\Behat\Context\SnippetAcceptingContext;
5+
use Behat\Behat\Context\Context;
66
use Behat\Behat\EventDispatcher\Event\OutlineTested;
77
use Behat\Behat\Hook\Scope\AfterScenarioScope;
88
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
@@ -28,10 +28,8 @@
2828

2929
/**
3030
* Features context.
31-
*
32-
* @phpstan-ignore class.implementsDeprecatedInterface
3331
*/
34-
class FeatureContext implements SnippetAcceptingContext {
32+
class FeatureContext implements Context {
3533

3634
use GivenStepDefinitions;
3735
use ThenStepDefinitions;
@@ -280,9 +278,6 @@ private static function running_with_code_coverage() {
280278
return \in_array( $with_code_coverage, [ 'true', '1' ], true );
281279
}
282280

283-
/**
284-
* @AfterSuite
285-
*/
286281
public static function merge_coverage_reports(): void {
287282
if ( ! self::running_with_code_coverage() ) {
288283
return;
@@ -435,13 +430,13 @@ private static function get_process_env_variables(): array {
435430
throw new RuntimeException( 'Could not find WP-CLI binary path.' );
436431
}
437432

438-
wp_cli_behat_env_debug( "WP-CLI binary path: {$bin_path}" );
433+
self::debug( "WP-CLI binary path: {$bin_path}" );
439434

440435
$bin = Utils\is_windows() ? 'wp.bat' : 'wp';
441436
$full_bin_path = $bin_path . DIRECTORY_SEPARATOR . $bin;
442437

443438
if ( ! is_executable( $full_bin_path ) ) {
444-
wp_cli_behat_env_debug( "WARNING: File named '{$bin}' found in the provided/detected binary path is not executable." );
439+
self::debug( "WARNING: File named '{$bin}' found in the provided/detected binary path is not executable." );
445440
}
446441

447442
$path_separator = Utils\is_windows() ? ';' : ':';
@@ -510,9 +505,9 @@ private static function get_process_env_variables(): array {
510505
}
511506

512507
// Dump environment for debugging purposes, but before adding the GitHub token.
513-
wp_cli_behat_env_debug( 'Environment:' );
508+
self::debug( 'Environment:' );
514509
foreach ( $env as $key => $value ) {
515-
wp_cli_behat_env_debug( " [{$key}] => {$value}" );
510+
self::debug( " [{$key}] => {$value}" );
516511
}
517512

518513
$github_token = getenv( 'GITHUB_TOKEN' );
@@ -663,6 +658,8 @@ private static function cache_wp_files( $version = '' ): void {
663658
* @BeforeSuite
664659
*/
665660
public static function prepare( BeforeSuiteScope $scope ): void {
661+
self::bootstrap_feature_context();
662+
666663
// Test performance statistics - useful for detecting slow tests.
667664
self::$log_run_times = getenv( 'WP_CLI_TEST_LOG_RUN_TIMES' );
668665
if ( false !== self::$log_run_times ) {
@@ -705,6 +702,8 @@ public static function afterSuite( AfterSuiteScope $scope ): void {
705702
if ( self::$log_run_times ) {
706703
self::log_run_times_after_suite( $scope );
707704
}
705+
706+
self::merge_coverage_reports();
708707
}
709708

710709
/**
@@ -893,6 +892,74 @@ public function __construct() {
893892
$this->set_cache_dir();
894893
}
895894

895+
/**
896+
* @param string $message
897+
*/
898+
protected static function debug( $message ): void { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
899+
if ( ! getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' ) ) {
900+
return;
901+
}
902+
903+
echo "{$message}\n";
904+
}
905+
906+
/**
907+
* Load required support files as needed before heading into the Behat context.
908+
*/
909+
protected static function bootstrap_feature_context(): void {
910+
$vendor_folder = self::get_vendor_dir();
911+
self::debug( "Vendor folder location: {$vendor_folder}" );
912+
913+
// Didn't manage to detect a valid vendor folder.
914+
if ( empty( $vendor_folder ) ) {
915+
return;
916+
}
917+
918+
// We assume the vendor folder is located in the project root folder.
919+
$project_folder = dirname( $vendor_folder );
920+
921+
$framework_folder = self::get_framework_dir();
922+
self::debug( "Framework folder location: {$framework_folder}" );
923+
924+
// Load helper functionality that is needed for the tests.
925+
require_once "{$framework_folder}/php/utils.php";
926+
require_once "{$framework_folder}/php/WP_CLI/Process.php";
927+
require_once "{$framework_folder}/php/WP_CLI/ProcessRun.php";
928+
929+
// Manually load Composer file includes by generating a config with require:
930+
// statements for each file.
931+
$project_composer = "{$project_folder}/composer.json";
932+
if ( ! file_exists( $project_composer ) ) {
933+
return;
934+
}
935+
936+
$composer = json_decode( (string) file_get_contents( $project_composer ) );
937+
if ( empty( $composer->autoload->files ) ) {
938+
return;
939+
}
940+
941+
$contents = "require:\n";
942+
foreach ( $composer->autoload->files as $file ) {
943+
$contents .= " - {$project_folder}/{$file}\n";
944+
}
945+
946+
$temp_folder = sys_get_temp_dir() . '/wp-cli-package-test';
947+
if (
948+
! is_dir( $temp_folder )
949+
&& ! mkdir( $temp_folder )
950+
&& ! is_dir( $temp_folder )
951+
) {
952+
return;
953+
}
954+
955+
$project_config = "{$temp_folder}/config.yml";
956+
file_put_contents( $project_config, $contents );
957+
putenv( 'WP_CLI_CONFIG_PATH=' . $project_config );
958+
959+
self::debug( "Project config file location: {$project_config}" );
960+
self::debug( "Project config:\n{$contents}" );
961+
}
962+
896963
/**
897964
* Replace standard {VARIABLE_NAME} variables and the special {INVOKE_WP_CLI_WITH_PHP_ARGS-args} and {WP_VERSION-version-latest} variables.
898965
* Note that standard variable names can only contain uppercase letters, digits and underscores and cannot begin with a digit.
@@ -1853,73 +1920,3 @@ private static function log_proc_method_run_time( $key, $start_time ): void {
18531920
++self::$proc_method_run_times[ $key ][1];
18541921
}
18551922
}
1856-
1857-
1858-
/**
1859-
* @param string $message
1860-
*/
1861-
function wp_cli_behat_env_debug( $message ): void { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
1862-
if ( ! getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' ) ) {
1863-
return;
1864-
}
1865-
1866-
echo "{$message}\n";
1867-
}
1868-
1869-
/**
1870-
* Load required support files as needed before heading into the Behat context.
1871-
*/
1872-
function wpcli_bootstrap_behat_feature_context(): void {
1873-
$vendor_folder = FeatureContext::get_vendor_dir();
1874-
wp_cli_behat_env_debug( "Vendor folder location: {$vendor_folder}" );
1875-
1876-
// Didn't manage to detect a valid vendor folder.
1877-
if ( empty( $vendor_folder ) ) {
1878-
return;
1879-
}
1880-
1881-
// We assume the vendor folder is located in the project root folder.
1882-
$project_folder = dirname( $vendor_folder );
1883-
1884-
$framework_folder = FeatureContext::get_framework_dir();
1885-
wp_cli_behat_env_debug( "Framework folder location: {$framework_folder}" );
1886-
1887-
// Load helper functionality that is needed for the tests.
1888-
require_once "{$framework_folder}/php/utils.php";
1889-
require_once "{$framework_folder}/php/WP_CLI/ProcessRun.php";
1890-
1891-
// Manually load Composer file includes by generating a config with require:
1892-
// statements for each file.
1893-
$project_composer = "{$project_folder}/composer.json";
1894-
if ( ! file_exists( $project_composer ) ) {
1895-
return;
1896-
}
1897-
1898-
$composer = json_decode( (string) file_get_contents( $project_composer ) );
1899-
if ( empty( $composer->autoload->files ) ) {
1900-
return;
1901-
}
1902-
1903-
$contents = "require:\n";
1904-
foreach ( $composer->autoload->files as $file ) {
1905-
$contents .= " - {$project_folder}/{$file}\n";
1906-
}
1907-
1908-
$temp_folder = sys_get_temp_dir() . '/wp-cli-package-test';
1909-
if (
1910-
! is_dir( $temp_folder )
1911-
&& ! mkdir( $temp_folder )
1912-
&& ! is_dir( $temp_folder )
1913-
) {
1914-
return;
1915-
}
1916-
1917-
$project_config = "{$temp_folder}/config.yml";
1918-
file_put_contents( $project_config, $contents );
1919-
putenv( 'WP_CLI_CONFIG_PATH=' . $project_config );
1920-
1921-
wp_cli_behat_env_debug( "Project config file location: {$project_config}" );
1922-
wp_cli_behat_env_debug( "Project config:\n{$contents}" );
1923-
}
1924-
1925-
wpcli_bootstrap_behat_feature_context();

0 commit comments

Comments
 (0)