Skip to content
Merged
Changes from all commits
Commits
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
38 changes: 32 additions & 6 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,21 @@
}

/**
* @AfterSuite
* Whether tests are currently running with code coverage collection.
*
* @return bool
*/
public static function merge_coverage_reports(): void {
private static function running_with_code_coverage() {

Check warning on line 276 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L276

Added line #L276 was not covered by tests
$with_code_coverage = (string) getenv( 'WP_CLI_TEST_COVERAGE' );

if ( ! \in_array( $with_code_coverage, [ 'true', '1' ], true ) ) {
return \in_array( $with_code_coverage, [ 'true', '1' ], true );

Check warning on line 279 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L279

Added line #L279 was not covered by tests
}

/**
* @AfterSuite
*/
public static function merge_coverage_reports(): void {
if ( ! self::running_with_code_coverage() ) {

Check warning on line 286 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L285-L286

Added lines #L285 - L286 were not covered by tests
return;
}

Expand Down Expand Up @@ -436,9 +445,7 @@
'TEST_RUN_DIR' => self::$behat_run_dir,
];

$with_code_coverage = (string) getenv( 'WP_CLI_TEST_COVERAGE' );

if ( \in_array( $with_code_coverage, [ 'true', '1' ], true ) ) {
if ( self::running_with_code_coverage() ) {

Check warning on line 448 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L448

Added line #L448 was not covered by tests
$has_coverage_driver = ( new Runtime() )->hasXdebug() || ( new Runtime() )->hasPCOV();

if ( ! $has_coverage_driver ) {
Expand Down Expand Up @@ -1021,14 +1028,27 @@
public function build_phar( $version = 'same' ): void {
$this->variables['PHAR_PATH'] = $this->variables['RUN_DIR'] . '/' . uniqid( 'wp-cli-build-', true ) . '.phar';

$is_bundle = false;

Check warning on line 1031 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1031

Added line #L1031 was not covered by tests

// Test running against a package installed as a WP-CLI dependency
// WP-CLI bundle installed as a project dependency
$make_phar_path = self::get_vendor_dir() . '/wp-cli/wp-cli-bundle/utils/make-phar.php';
if ( ! file_exists( $make_phar_path ) ) {
// Running against WP-CLI bundle proper
$is_bundle = true;

Check warning on line 1038 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1038

Added line #L1038 was not covered by tests

$make_phar_path = self::get_vendor_dir() . '/../utils/make-phar.php';
}

// Temporarily modify the Composer autoloader used within the Phar
// so that it doesn't clash if autoloading is already happening outside of it,
// for example when generating code coverage.
// This modifies composer.json.
if ( $is_bundle && self::running_with_code_coverage() ) {
$this->composer_command( 'config autoloader-suffix "WpCliTestsPhar" --working-dir=' . dirname( self::get_vendor_dir() ) );
$this->composer_command( 'dump-autoload --working-dir=' . dirname( self::get_vendor_dir() ) );

Check warning on line 1049 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1047-L1049

Added lines #L1047 - L1049 were not covered by tests
}

$this->proc(
Utils\esc_cmd(
'php -dphar.readonly=0 %1$s %2$s --version=%3$s && chmod +x %2$s',
Expand All @@ -1037,6 +1057,12 @@
$version
)
)->run_check();

// Revert the suffix change again
if ( $is_bundle && self::running_with_code_coverage() ) {
$this->composer_command( 'config autoloader-suffix "WpCliBundle" --working-dir=' . dirname( self::get_vendor_dir() ) );
$this->composer_command( 'dump-autoload --working-dir=' . dirname( self::get_vendor_dir() ) );

Check warning on line 1064 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1062-L1064

Added lines #L1062 - L1064 were not covered by tests
}
}

/**
Expand Down