From 4612a1a070b12af89a5dddd95131d915ece7866b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 18 Nov 2026 06:31:30 +0000 Subject: [PATCH 1/2] Fix PHPUnit stat() warnings and Windows Behat failures Create the default composer.json before writing it, as Composer's atomic file replacement calls a silenced stat() on the missing file, which PHPUnit 11 still reports as a warning. Move the ZipArchive scripts in the remote zip scenarios into a PHP file, since cmd.exe on Windows does not support single-quoted arguments. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5nV4LG7puMYjXm13Nd --- features/package-install.feature | 20 ++++++++++++++++++-- src/Package_Command.php | 7 +++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/features/package-install.feature b/features/package-install.feature index f417a155..9abb2faf 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -1027,7 +1027,15 @@ Feature: Install WP-CLI packages "type": "wp-cli-package" } """ - And I run `php -r '$zip = new ZipArchive(); $zip->open( "remote-zip-test-command.zip", ZipArchive::CREATE | ZipArchive::OVERWRITE ); $zip->addFromString( "remote-zip-test-command/composer.json", file_get_contents( "remote-zip-test-command/composer.json" ) ); $zip->close();'` + And a create-zip.php file: + """ + open( 'remote-zip-test-command.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE ); + $zip->addFromString( 'remote-zip-test-command/composer.json', file_get_contents( 'remote-zip-test-command/composer.json' ) ); + $zip->close(); + """ + And I run `php create-zip.php` And a PHP built-in web server When I run `wp package install http://localhost:8080/remote-zip-test-command.zip` @@ -1055,7 +1063,15 @@ Feature: Install WP-CLI packages "type": "wp-cli-package" } """ - And I run `php -r '$zip = new ZipArchive(); $zip->open( "remote-zip-flat-command.zip", ZipArchive::CREATE | ZipArchive::OVERWRITE ); $zip->addFromString( "composer.json", file_get_contents( "composer-flat.json" ) ); $zip->close();'` + And a create-zip.php file: + """ + open( 'remote-zip-flat-command.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE ); + $zip->addFromString( 'composer.json', file_get_contents( 'composer-flat.json' ) ); + $zip->close(); + """ + And I run `php create-zip.php` And a PHP built-in web server When I run `wp package install http://localhost:8080/remote-zip-flat-command.zip` diff --git a/src/Package_Command.php b/src/Package_Command.php index d4642647..5c640416 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -1305,6 +1305,13 @@ private function create_default_composer_json( $composer_path ) { $composer_path = Path::trailingslashit( $composer_dir ) . Path::basename( $composer_path ); + // Make sure the file exists before writing to it, as Composer's + // atomic file replacement otherwise triggers a (silenced) `stat()` + // warning for the missing file. + if ( ! file_exists( $composer_path ) ) { + @touch( $composer_path ); // @codingStandardsIgnoreLine + } + $json_file = new JsonFile( $composer_path ); $repositories = (object) [ From b607365cf40ac4480894ebf531235f5f8721b0f3 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 18 Nov 2026 06:36:56 +0000 Subject: [PATCH 2/2] Remove empty composer.json if writing the default one fails Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5nV4LG7puMYjXm13Nd --- src/Package_Command.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 5c640416..e01a2cb5 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -1308,8 +1308,9 @@ private function create_default_composer_json( $composer_path ) { // Make sure the file exists before writing to it, as Composer's // atomic file replacement otherwise triggers a (silenced) `stat()` // warning for the missing file. + $created = false; if ( ! file_exists( $composer_path ) ) { - @touch( $composer_path ); // @codingStandardsIgnoreLine + $created = @touch( $composer_path ); // @codingStandardsIgnoreLine } $json_file = new JsonFile( $composer_path ); @@ -1335,6 +1336,10 @@ private function create_default_composer_json( $composer_path ) { try { $json_file->write( $options ); } catch ( Exception $e ) { + // Don't leave an empty composer.json behind, so that a later run can retry. + if ( $created ) { + @unlink( $composer_path ); // @codingStandardsIgnoreLine + } WP_CLI::error( $e->getMessage() ); }