From e6d1bb43ac8e2b84e4bda89882a30ad41ae83822 Mon Sep 17 00:00:00 2001 From: Moshe Weitzman Date: Mon, 17 Jun 2024 07:41:43 -0400 Subject: [PATCH] Fix #6025. drush pmu throws array to string conversion warning (#6036) * Fix #6025. drush pmu throws array to string conversion warning * phpstan --- src/Commands/pm/PmCommands.php | 9 ++++++--- tests/functional/PmInUnListInfoTest.php | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Commands/pm/PmCommands.php b/src/Commands/pm/PmCommands.php index 2e29f19e01..e8119e2c73 100644 --- a/src/Commands/pm/PmCommands.php +++ b/src/Commands/pm/PmCommands.php @@ -187,13 +187,16 @@ public function uninstall(array $modules): void #[CLI\Hook(type: HookManager::ARGUMENT_VALIDATOR, target: PmCommands::UNINSTALL)] public function validateUninstall(CommandData $commandData): void { + $list = []; if ($modules = $commandData->input()->getArgument('modules')) { $modules = StringUtils::csvToArray($modules); if ($validation_reasons = $this->getModuleInstaller()->validateUninstall($modules)) { - foreach ($validation_reasons as $module => $reason) { - $reasons[$module] = "$module: " . $reason; + foreach ($validation_reasons as $module => $reasons) { + foreach ($reasons as $reason) { + $list[] = "$module: " . (string)$reason; + } } - throw new \Exception(implode("/n", $reasons)); + throw new \Exception(implode("/n", $list)); } } } diff --git a/tests/functional/PmInUnListInfoTest.php b/tests/functional/PmInUnListInfoTest.php index 97a0dbd175..1736bc5fb7 100644 --- a/tests/functional/PmInUnListInfoTest.php +++ b/tests/functional/PmInUnListInfoTest.php @@ -88,5 +88,10 @@ public function testEnDisUnList() $this->drush(PmCommands::UNINSTALL, ['drush_empty_module'], [], null, null, self::EXIT_ERROR); $out = $this->getErrorOutput(); $this->assertStringContainsString('The following module(s) are not installed', $out); + + // Test uninstall of required module, and reason printing + $this->drush(PmCommands::UNINSTALL, ['user'], [], null, null, self::EXIT_ERROR); + $out = $this->getErrorOutput(); + $this->assertStringContainsString('is required', $out); } }