function RecipeTestTrait::applyRecipe

Same name and namespace in other branches
  1. 10 core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeTestTrait.php \Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait::applyRecipe()

Applies a recipe to the site.

Parameters

string $path: The path of the recipe to apply. Must be a directory.

int $expected_exit_code: The expected exit code of the `drupal recipe` process. Defaults to 0, which indicates that no error occurred.

Return value

\Symfony\Component\Process\Process The `drupal recipe` command process, after having run.

9 calls to RecipeTestTrait::applyRecipe()
CoreRecipesTest::testApplyRecipe in core/tests/Drupal/FunctionalTests/Core/Recipe/CoreRecipesTest.php
Test the recipe apply.
RecipeCommandTest::testErrorOnNonExistentDirectory in core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeCommandTest.php
Tests the recipe command with a non-existent directory.
RecipeCommandTest::testExceptionOnRollback in core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeCommandTest.php
Tests that errors during config rollback won't steamroll validation errors.
RecipeCommandTest::testRecipeCommand in core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeCommandTest.php
RollbackTest::testRollbackForInvalidConfig in core/tests/Drupal/FunctionalTests/Core/Recipe/RollbackTest.php
@testWith ["invalid_config", "core.date_format.invalid"] ["recipe_depend_on_invalid", "core.date_format.invalid"] ["recipe_depend_on_invalid_config_and_valid_modules", "core.date_format.invalid"]

... See full list

File

core/tests/Drupal/FunctionalTests/Core/Recipe/RecipeTestTrait.php, line 59

Class

RecipeTestTrait
Contains helper methods for interacting with recipes in functional tests.

Namespace

Drupal\FunctionalTests\Core\Recipe

Code

protected function applyRecipe(string $path, int $expected_exit_code = 0) : Process {
    assert($this instanceof BrowserTestBase);
    $arguments = [
        (new PhpExecutableFinder())->find(),
        'core/scripts/drupal',
        'recipe',
        $path,
    ];
    $process = (new Process($arguments))->setWorkingDirectory($this->getDrupalRoot())
        ->setEnv([
        'DRUPAL_DEV_SITE_PATH' => $this->siteDirectory,
        // Ensure that the command boots Drupal into a state where it knows it's
        // a test site.
        // @see drupal_valid_test_ua()
'HTTP_USER_AGENT' => drupal_generate_test_ua($this->databasePrefix),
    ])
        ->setTimeout(500);
    $process->run();
    $this->assertSame($expected_exit_code, $process->getExitCode(), $process->getErrorOutput());
    // Applying a recipe:
    // - creates new checkpoints, hence the "state" service in the test runner
    //   is outdated
    // - may install modules, which would cause the entire container in the test
    //   runner to be outdated.
    // Hence the entire environment must be rebuilt for assertions to target the
    // actual post-recipe-application result.
    // @see \Drupal\Core\Config\Checkpoint\LinearHistory::__construct()
    $this->rebuildAll();
    return $process;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.