From 9fcac29f275546d29d98e8627ecba4be80b47665 Mon Sep 17 00:00:00 2001 From: Manish Songirkar Date: Wed, 2 Dec 2026 19:11:07 +0530 Subject: [PATCH 1/2] fix(package): count each package once when `update` names it twice `wp package update A A` kept the duplicate name in `$packages_to_update`. `count()` and `array_intersect()` both kept the duplicate, so the two counts matched and the plural message "All 2 packages updated successfully." was printed for one package. Remove duplicate names after the validation loop with `array_unique()`. Add a Behat scenario that names one package twice and expects "Package updated successfully.". Fixes #267 --- features/package-update.feature | 22 ++++++++++++++++++++++ src/Package_Command.php | 2 ++ 2 files changed, 24 insertions(+) diff --git a/features/package-update.feature b/features/package-update.feature index b2f72295..faa87dd9 100644 --- a/features/package-update.feature +++ b/features/package-update.feature @@ -132,6 +132,28 @@ Feature: Update WP-CLI packages | name | update | | wp-cli-test/updateable-package | none | + Scenario: Update a package named more than once counts it once + Given an empty directory + + When I run `wp package install wp-cli-test/updateable-package:v3.0.0` + Then STDOUT should contain: + """ + Success: Package installed. + """ + + When I run `wp eval "file_put_contents( '{PACKAGE_PATH}composer.json', str_replace( 'v3.0.0', '>=3.0.0', file_get_contents( '{PACKAGE_PATH}composer.json' ) ) );" --skip-wordpress` + Then the return code should be 0 + + When I run `wp package update wp-cli-test/updateable-package wp-cli-test/updateable-package` + Then STDOUT should contain: + """ + Success: Package updated successfully. + """ + And STDOUT should not contain: + """ + All 2 packages + """ + Scenario: Update multiple specific packages by name Given an empty directory diff --git a/src/Package_Command.php b/src/Package_Command.php index 73085008..44c7f6d6 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -702,6 +702,8 @@ public function update( $args, $assoc_args = [] ) { // Use the package's pretty name (case-sensitive) from composer $packages_to_update[] = $package['name']; } + // Report each package once, even if it was named more than once. + $packages_to_update = array_values( array_unique( $packages_to_update ) ); } $this->get_installed_packages(); // Validate composer.json before starting the child. From a341aef70371ab826158e1033612b2ade3ccfa70 Mon Sep 17 00:00:00 2001 From: Manish Songirkar Date: Wed, 2 Dec 2026 19:54:19 +0530 Subject: [PATCH 2/2] fix(package): remove duplicate names before looking up packages Call array_unique() on the arguments before the validation loop, instead of on the resolved names after it. Each package is now looked up once, so a repeated name no longer costs extra composer.json reads. Addresses review feedback on #269. --- src/Package_Command.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 44c7f6d6..21e2c1af 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -694,7 +694,8 @@ public function update( $args, $assoc_args = [] ) { // Validate package names if provided $packages_to_update = []; if ( ! empty( $args ) ) { - foreach ( $args as $package_name ) { + // Look up and report each package once, even if it was named more than once. + foreach ( array_unique( $args ) as $package_name ) { $package = $this->get_installed_package_by_name( $package_name ); if ( false === $package ) { WP_CLI::error( sprintf( "Package '%s' is not installed.", $package_name ) ); @@ -702,8 +703,6 @@ public function update( $args, $assoc_args = [] ) { // Use the package's pretty name (case-sensitive) from composer $packages_to_update[] = $package['name']; } - // Report each package once, even if it was named more than once. - $packages_to_update = array_values( array_unique( $packages_to_update ) ); } $this->get_installed_packages(); // Validate composer.json before starting the child.