@@ -188,12 +188,21 @@ public static function forget_feature( AfterFeatureScope $scope ) {
188188 }
189189
190190 /**
191- * @AfterSuite
191+ * Whether tests are currently running with code coverage collection.
192+ *
193+ * @return bool
192194 */
193- public static function merge_coverage_reports () {
195+ private static function running_with_code_coverage () {
194196 $ with_code_coverage = (string ) getenv ( 'WP_CLI_TEST_COVERAGE ' );
195197
196- if ( ! \in_array ( $ with_code_coverage , [ 'true ' , '1 ' ], true ) ) {
198+ return \in_array ( $ with_code_coverage , [ 'true ' , '1 ' ], true );
199+ }
200+
201+ /**
202+ * @AfterSuite
203+ */
204+ public static function merge_coverage_reports () {
205+ if ( self ::running_with_code_coverage () ) {
197206 return ;
198207 }
199208
@@ -354,9 +363,7 @@ private static function get_process_env_variables() {
354363 'TEST_RUN_DIR ' => self ::$ behat_run_dir ,
355364 ];
356365
357- $ with_code_coverage = (string ) getenv ( 'WP_CLI_TEST_COVERAGE ' );
358-
359- if ( \in_array ( $ with_code_coverage , [ 'true ' , '1 ' ], true ) ) {
366+ if ( self ::running_with_code_coverage () ) {
360367 $ has_coverage_driver = ( new Runtime () )->hasXdebug () || ( new Runtime () )->hasPCOV ();
361368
362369 if ( ! $ has_coverage_driver ) {
@@ -929,7 +936,7 @@ public function build_phar( $version = 'same' ) {
929936 // so that it doesn't clash if autoloading is already happening outside of it,
930937 // for example when generating code coverage.
931938 // This modifies composer.json.
932- if ( $ is_bundle ) {
939+ if ( $ is_bundle && self :: running_with_code_coverage () ) {
933940 $ this ->composer_command ( 'config autoloader-suffix "WpCliTestsPhar" --working-dir= ' . dirname ( self ::get_vendor_dir () ) );
934941 $ this ->composer_command ( 'dump-autoload --working-dir= ' . dirname ( self ::get_vendor_dir () ) );
935942 }
@@ -944,7 +951,7 @@ public function build_phar( $version = 'same' ) {
944951 )->run_check ();
945952
946953 // Revert the suffix change again
947- if ( $ is_bundle ) {
954+ if ( $ is_bundle && self :: running_with_code_coverage () ) {
948955 $ this ->composer_command ( 'config autoloader-suffix "WpCliBundle" --working-dir= ' . dirname ( self ::get_vendor_dir () ) );
949956 $ this ->composer_command ( 'dump-autoload --working-dir= ' . dirname ( self ::get_vendor_dir () ) );
950957 }
0 commit comments