Skip to content

Commit 1e77437

Browse files
authored
Merge branch 'main' into add/209-updated
2 parents 3e53b19 + c6fde56 commit 1e77437

File tree

5 files changed

+49
-26
lines changed

5 files changed

+49
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ phpunit.xml
1212
phpcs.xml
1313
.phpcs.xml
1414
.phpunit.result.cache
15+
.phpunit.cache
1516
build/logs

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"wp-cli/eval-command": "^1 || ^2",
2424
"wp-cli/wp-cli": "^2.12",
2525
"wp-coding-standards/wpcs": "^3",
26-
"yoast/phpunit-polyfills": "^1.0.3 || ^2.0.1"
26+
"yoast/phpunit-polyfills": "^4.0.0"
2727
},
2828
"require-dev": {
2929
"roave/security-advisories": "dev-latest"

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
<?xml version="1.0" ?>
12
<phpunit
23
bootstrap="tests/bootstrap.php"
34
colors="true"
45
convertErrorsToExceptions="true"
56
convertWarningsToExceptions="true"
67
convertNoticesToExceptions="true"
78
convertDeprecationsToExceptions="true"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
811
>
912
<testsuites>
1013
<testsuite name="default">

src/Context/FeatureContext.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,21 @@ public static function forget_feature( AfterFeatureScope $scope ): void {
270270
}
271271

272272
/**
273-
* @AfterSuite
273+
* Whether tests are currently running with code coverage collection.
274+
*
275+
* @return bool
274276
*/
275-
public static function merge_coverage_reports(): void {
277+
private static function running_with_code_coverage() {
276278
$with_code_coverage = (string) getenv( 'WP_CLI_TEST_COVERAGE' );
277279

278-
if ( ! \in_array( $with_code_coverage, [ 'true', '1' ], true ) ) {
280+
return \in_array( $with_code_coverage, [ 'true', '1' ], true );
281+
}
282+
283+
/**
284+
* @AfterSuite
285+
*/
286+
public static function merge_coverage_reports(): void {
287+
if ( ! self::running_with_code_coverage() ) {
279288
return;
280289
}
281290

@@ -437,9 +446,7 @@ private static function get_process_env_variables(): array {
437446
'TEST_RUN_DIR' => self::$behat_run_dir,
438447
];
439448

440-
$with_code_coverage = (string) getenv( 'WP_CLI_TEST_COVERAGE' );
441-
442-
if ( \in_array( $with_code_coverage, [ 'true', '1' ], true ) ) {
449+
if ( self::running_with_code_coverage() ) {
443450
$has_coverage_driver = ( new Runtime() )->hasXdebug() || ( new Runtime() )->hasPCOV();
444451

445452
if ( ! $has_coverage_driver ) {
@@ -1023,14 +1030,27 @@ public function create_run_dir(): void {
10231030
public function build_phar( $version = 'same' ): void {
10241031
$this->variables['PHAR_PATH'] = $this->variables['RUN_DIR'] . '/' . uniqid( 'wp-cli-build-', true ) . '.phar';
10251032

1033+
$is_bundle = false;
1034+
10261035
// Test running against a package installed as a WP-CLI dependency
10271036
// WP-CLI bundle installed as a project dependency
10281037
$make_phar_path = self::get_vendor_dir() . '/wp-cli/wp-cli-bundle/utils/make-phar.php';
10291038
if ( ! file_exists( $make_phar_path ) ) {
10301039
// Running against WP-CLI bundle proper
1040+
$is_bundle = true;
1041+
10311042
$make_phar_path = self::get_vendor_dir() . '/../utils/make-phar.php';
10321043
}
10331044

1045+
// Temporarily modify the Composer autoloader used within the Phar
1046+
// so that it doesn't clash if autoloading is already happening outside of it,
1047+
// for example when generating code coverage.
1048+
// This modifies composer.json.
1049+
if ( $is_bundle && self::running_with_code_coverage() ) {
1050+
$this->composer_command( 'config autoloader-suffix "WpCliTestsPhar" --working-dir=' . dirname( self::get_vendor_dir() ) );
1051+
$this->composer_command( 'dump-autoload --working-dir=' . dirname( self::get_vendor_dir() ) );
1052+
}
1053+
10341054
$this->proc(
10351055
Utils\esc_cmd(
10361056
'php -dphar.readonly=0 %1$s %2$s --version=%3$s && chmod +x %2$s',
@@ -1039,6 +1059,12 @@ public function build_phar( $version = 'same' ): void {
10391059
$version
10401060
)
10411061
)->run_check();
1062+
1063+
// Revert the suffix change again
1064+
if ( $is_bundle && self::running_with_code_coverage() ) {
1065+
$this->composer_command( 'config autoloader-suffix "WpCliBundle" --working-dir=' . dirname( self::get_vendor_dir() ) );
1066+
$this->composer_command( 'dump-autoload --working-dir=' . dirname( self::get_vendor_dir() ) );
1067+
}
10421068
}
10431069

10441070
/**

tests/tests/TestBehatTags.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use WP_CLI\Tests\TestCase;
44
use WP_CLI\Utils;
5+
use PHPUnit\Framework\Attributes\DataProvider;
56

67
class TestBehatTags extends TestCase {
78

@@ -37,6 +38,7 @@ protected function tear_down(): void {
3738
* @param string $env
3839
* @param string $expected
3940
*/
41+
#[DataProvider( 'data_behat_tags_wp_version_github_token' )] // phpcs:ignore PHPCompatibility.Attributes.NewAttributes.PHPUnitAttributeFound
4042
public function test_behat_tags_wp_version_github_token( $env, $expected ): void {
4143
$env_wp_version = getenv( 'WP_VERSION' );
4244
$env_github_token = getenv( 'GITHUB_TOKEN' );
@@ -110,25 +112,7 @@ public function test_behat_tags_php_version(): void {
110112
$contents = '';
111113
$expected = '';
112114

113-
if ( '5.3' === $php_version ) {
114-
$contents = '@require-php-5.2 @require-php-5.3 @require-php-5.4 @less-than-php-5.2 @less-than-php-5.3 @less-than-php-5.4';
115-
116-
} elseif ( '5.4' === $php_version ) {
117-
$contents = '@require-php-5.3 @require-php-5.4 @require-php-5.5 @less-than-php-5.3 @less-than-php-5.4 @less-than-php-5.5';
118-
119-
} elseif ( '5.5' === $php_version ) {
120-
$contents = '@require-php-5.4 @require-php-5.5 @require-php-5.6 @less-than-php-5.4 @less-than-php-5.5 @less-than-php-5.6';
121-
122-
} elseif ( '5.6' === $php_version ) {
123-
$contents = '@require-php-5.5 @require-php-5.6 @require-php-7.0 @less-than-php-5.5 @less-than-php-5.6 @less-than-php-7.0';
124-
125-
} elseif ( '7.0' === $php_version ) {
126-
$contents = '@require-php-5.6 @require-php-7.0 @require-php-7.1 @less-than-php-5.6 @less-than-php-7.0 @less-than-php-7.1';
127-
128-
} elseif ( '7.1' === $php_version ) {
129-
$contents = '@require-php-7.0 @require-php-7.1 @require-php-7.2 @less-than-php-7.0 @less-than-php-7.1 @less-than-php-7.2';
130-
131-
} elseif ( '7.2' === $php_version ) {
115+
if ( '7.2' === $php_version ) {
132116
$contents = '@require-php-7.1 @require-php-7.2 @require-php-7.3 @less-than-php-7.1 @less-than-php-7.2 @less-than-php-7.3';
133117
134118
} elseif ( '7.3' === $php_version ) {
@@ -143,6 +127,15 @@ public function test_behat_tags_php_version(): void {
143127
} elseif ( '8.1' === $php_version ) {
144128
$contents = '@require-php-8.0 @require-php-8.1 @require-php-8.2 @less-than-php-8.0 @less-than-php-8.1 @less-than-php-8.2';
145129
130+
} elseif ( '8.2' === $php_version ) {
131+
$contents = '@require-php-8.0 @require-php-8.1 @require-php-8.2 @require-php-8.3 @less-than-php-8.0 @less-than-php-8.1 @less-than-php-8.2 @less-than-php-8.3 @less-than-php-8.4';
132+
133+
} elseif ( '8.3' === $php_version ) {
134+
$contents = '@require-php-8.1 @require-php-8.2 @require-php-8.3 @require-php-8.4 @less-than-php-8.0 @less-than-php-8.1 @less-than-php-8.2 @less-than-php-8.3 @less-than-php-8.4';
135+
136+
} elseif ( '8.4' === $php_version ) {
137+
$contents = '@require-php-8.2 @require-php-8.3 @require-php-8.4 @require-php-8.5 @less-than-php-8.0 @less-than-php-8.1 @less-than-php-8.2 @less-than-php-8.3 @less-than-php-8.4 @less-than-php-8.5';
138+
146139
} else {
147140
$this->markTestSkipped( "No test for PHP_VERSION $php_version." );
148141
}

0 commit comments

Comments
 (0)