From 58cd9ce0831b03c366ad90f2b8c5b1c4fb860d42 Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Mon, 20 May 2024 08:09:25 +1000 Subject: [PATCH] Issue #3447198 by phenaproxima, alexpott, nicxvan, larowlan: RecipeCommand mistakenly tries to apply a recipe even if you don't give it a valid directory (cherry picked from commit 389c2bee0ba3a13493dc6fddd9fa36895a9720e6) --- core/lib/Drupal/Core/Recipe/RecipeCommand.php | 1 + .../Core/Recipe/RecipeCommandTest.php | 12 ++++++++++++ .../FunctionalTests/Core/Recipe/RecipeTestTrait.php | 1 - 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Recipe/RecipeCommand.php b/core/lib/Drupal/Core/Recipe/RecipeCommand.php index 84ee9e2d654..6d6f496ada2 100644 --- a/core/lib/Drupal/Core/Recipe/RecipeCommand.php +++ b/core/lib/Drupal/Core/Recipe/RecipeCommand.php @@ -65,6 +65,7 @@ final class RecipeCommand extends Command { $recipe_path = $input->getArgument('path'); if (!is_string($recipe_path) || !is_dir($recipe_path)) { $io->error(sprintf('The supplied path %s is not a directory', $recipe_path)); + return 1; } // Recipes can only be applied to an already-installed site. $container = $this->boot()->getContainer(); diff --git a/core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeCommandTest.php b/core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeCommandTest.php index 39149729e78..390e5414c95 100644 --- a/core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeCommandTest.php +++ b/core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeCommandTest.php @@ -91,6 +91,18 @@ class RecipeCommandTest extends BrowserTestBase { $this->assertStringContainsString('There were validation errors in system.image:', $process->getErrorOutput()); } + /** + * Tests the recipe command with a non-existent directory. + */ + public function testErrorOnNonExistentDirectory(): void { + $process = $this->applyRecipe('core/tests/fixtures/recipes/does_not_exist', 1); + + // The directory error should be the only error visible. + $output = trim(preg_replace('/\s+/', ' ', $process->getOutput())); + $this->assertSame('[ERROR] The supplied path core/tests/fixtures/recipes/does_not_exist is not a directory', $output); + $this->assertEmpty($process->getErrorOutput()); + } + /** * Asserts that the current set of checkpoints matches the given labels. * diff --git a/core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeTestTrait.php b/core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeTestTrait.php index 601dced2963..fdd89ac217c 100644 --- a/core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeTestTrait.php +++ b/core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeTestTrait.php @@ -58,7 +58,6 @@ trait RecipeTestTrait { */ protected function applyRecipe(string $path, int $expected_exit_code = 0): Process { assert($this instanceof BrowserTestBase); - $this->assertDirectoryExists($path); $arguments = [ (new PhpExecutableFinder())->find(),