@@ -921,6 +921,23 @@ public function build_phar( $version = 'same' ) {
921
921
$ make_phar_path = self ::get_vendor_dir () . '/../utils/make-phar.php ' ;
922
922
}
923
923
924
+ // Temporarily modify the Composer autoloader used within the Phar
925
+ // so that it doesn't clash if autoloading is already happening outside of it,
926
+ // for example when generating code coverage.
927
+ // This modifies composer.json.
928
+ $ this ->proc (
929
+ Utils \esc_cmd (
930
+ 'composer config autoloader-suffix "WpCliTestsPhar" --working-dir=%s ' ,
931
+ dirname ( self ::get_vendor_dir () )
932
+ )
933
+ )->run_check ();
934
+ $ this ->proc (
935
+ Utils \esc_cmd (
936
+ 'composer dump-autoload --working-dir=%s ' ,
937
+ dirname ( self ::get_vendor_dir () )
938
+ )
939
+ )->run_check ();
940
+
924
941
$ this ->proc (
925
942
Utils \esc_cmd (
926
943
'php -dphar.readonly=0 %1$s %2$s --version=%3$s && chmod +x %2$s ' ,
@@ -929,6 +946,23 @@ public function build_phar( $version = 'same' ) {
929
946
$ version
930
947
)
931
948
)->run_check ();
949
+
950
+ // Revert the composer.json modification again
951
+ $ this ->proc (
952
+ Utils \esc_cmd (
953
+ 'composer config --unset autoloader-suffix --working-dir=%s ' ,
954
+ dirname ( self ::get_vendor_dir () )
955
+ )
956
+ )->run_check ();
957
+ // Prevent Composer from simply reusing the existing suffix.
958
+ unlink ( self ::get_vendor_dir () . '/autoload.php ' );
959
+ // Now it will use the content hash again.
960
+ $ this ->proc (
961
+ Utils \esc_cmd (
962
+ 'composer dump-autoload -d %s ' ,
963
+ dirname ( self ::get_vendor_dir () )
964
+ )
965
+ )->run_check ();
932
966
}
933
967
934
968
public function download_phar ( $ version = 'same ' ) {
0 commit comments