Skip to content

Commit 91d45f8

Browse files
authored
Merge branch 'main' into add/phpstan-enhancements
2 parents 17e4af9 + c6fde56 commit 91d45f8

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
@@ -27,7 +27,7 @@
2727
"wp-cli/eval-command": "^1 || ^2",
2828
"wp-cli/wp-cli": "^2.12",
2929
"wp-coding-standards/wpcs": "^3",
30-
"yoast/phpunit-polyfills": "^1.0.3 || ^2.0.1"
30+
"yoast/phpunit-polyfills": "^4.0.0"
3131
},
3232
"require-dev": {
3333
"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
@@ -271,12 +271,21 @@ public static function forget_feature( AfterFeatureScope $scope ): void {
271271
}
272272

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

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

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

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

446453
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
@@ -4,6 +4,7 @@
44

55
use WP_CLI\Tests\TestCase;
66
use WP_CLI\Utils;
7+
use PHPUnit\Framework\Attributes\DataProvider;
78

89
class TestBehatTags extends TestCase {
910

@@ -39,6 +40,7 @@ protected function tear_down(): void {
3940
* @param string $env
4041
* @param string $expected
4142
*/
43+
#[DataProvider( 'data_behat_tags_wp_version_github_token' )] // phpcs:ignore PHPCompatibility.Attributes.NewAttributes.PHPUnitAttributeFound
4244
public function test_behat_tags_wp_version_github_token( $env, $expected ): void {
4345
$env_wp_version = getenv( 'WP_VERSION' );
4446
$env_github_token = getenv( 'GITHUB_TOKEN' );
@@ -112,25 +114,7 @@ public function test_behat_tags_php_version(): void {
112114
$contents = '';
113115
$expected = '';
114116

115-
if ( '5.3' === $php_version ) {
116-
$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';
117-
118-
} elseif ( '5.4' === $php_version ) {
119-
$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';
120-
121-
} elseif ( '5.5' === $php_version ) {
122-
$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';
123-
124-
} elseif ( '5.6' === $php_version ) {
125-
$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';
126-
127-
} elseif ( '7.0' === $php_version ) {
128-
$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';
129-
130-
} elseif ( '7.1' === $php_version ) {
131-
$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';
132-
133-
} elseif ( '7.2' === $php_version ) {
117+
if ( '7.2' === $php_version ) {
134118
$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';
135119
136120
} elseif ( '7.3' === $php_version ) {
@@ -145,6 +129,15 @@ public function test_behat_tags_php_version(): void {
145129
} elseif ( '8.1' === $php_version ) {
146130
$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';
147131
132+
} elseif ( '8.2' === $php_version ) {
133+
$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';
134+
135+
} elseif ( '8.3' === $php_version ) {
136+
$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';
137+
138+
} elseif ( '8.4' === $php_version ) {
139+
$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';
140+
148141
} else {
149142
$this->markTestSkipped( "No test for PHP_VERSION $php_version." );
150143
}

0 commit comments

Comments
 (0)