Skip to content

Commit 7937288

Browse files
swissspidyclaude
andauthored
Fix PHPUnit stat() warnings and Windows Behat failures (#261)
* 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5nV4LG7puMYjXm13Nd * Remove empty composer.json if writing the default one fails Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5nV4LG7puMYjXm13Nd --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 21f7c72 commit 7937288

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎features/package-install.feature‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,15 @@ Feature: Install WP-CLI packages
10271027
"type": "wp-cli-package"
10281028
}
10291029
"""
1030-
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();'`
1030+
And a create-zip.php file:
1031+
"""
1032+
<?php
1033+
$zip = new ZipArchive();
1034+
$zip->open( 'remote-zip-test-command.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE );
1035+
$zip->addFromString( 'remote-zip-test-command/composer.json', file_get_contents( 'remote-zip-test-command/composer.json' ) );
1036+
$zip->close();
1037+
"""
1038+
And I run `php create-zip.php`
10311039
And a PHP built-in web server
10321040
10331041
When I run `wp package install http://localhost:8080/remote-zip-test-command.zip`
@@ -1055,7 +1063,15 @@ Feature: Install WP-CLI packages
10551063
"type": "wp-cli-package"
10561064
}
10571065
"""
1058-
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();'`
1066+
And a create-zip.php file:
1067+
"""
1068+
<?php
1069+
$zip = new ZipArchive();
1070+
$zip->open( 'remote-zip-flat-command.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE );
1071+
$zip->addFromString( 'composer.json', file_get_contents( 'composer-flat.json' ) );
1072+
$zip->close();
1073+
"""
1074+
And I run `php create-zip.php`
10591075
And a PHP built-in web server
10601076
10611077
When I run `wp package install http://localhost:8080/remote-zip-flat-command.zip`

‎src/Package_Command.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,14 @@ private function create_default_composer_json( $composer_path ) {
13051305

13061306
$composer_path = Path::trailingslashit( $composer_dir ) . Path::basename( $composer_path );
13071307

1308+
// Make sure the file exists before writing to it, as Composer's
1309+
// atomic file replacement otherwise triggers a (silenced) `stat()`
1310+
// warning for the missing file.
1311+
$created = false;
1312+
if ( ! file_exists( $composer_path ) ) {
1313+
$created = @touch( $composer_path ); // @codingStandardsIgnoreLine
1314+
}
1315+
13081316
$json_file = new JsonFile( $composer_path );
13091317

13101318
$repositories = (object) [
@@ -1328,6 +1336,10 @@ private function create_default_composer_json( $composer_path ) {
13281336
try {
13291337
$json_file->write( $options );
13301338
} catch ( Exception $e ) {
1339+
// Don't leave an empty composer.json behind, so that a later run can retry.
1340+
if ( $created ) {
1341+
@unlink( $composer_path ); // @codingStandardsIgnoreLine
1342+
}
13311343
WP_CLI::error( $e->getMessage() );
13321344
}
13331345

0 commit comments

Comments
 (0)