class RecipeConfiguratorTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Recipe/RecipeConfiguratorTest.php \Drupal\KernelTests\Core\Recipe\RecipeConfiguratorTest

@coversDefaultClass \Drupal\Core\Recipe\RecipeConfigurator
@group Recipe

Hierarchy

Expanded class hierarchy of RecipeConfiguratorTest

File

core/tests/Drupal/KernelTests/Core/Recipe/RecipeConfiguratorTest.php, line 16

Namespace

Drupal\KernelTests\Core\Recipe
View source
class RecipeConfiguratorTest extends KernelTestBase {
  public function testRecipeConfigurator() : void {
    $recipe_configurator = new RecipeConfigurator([
      'install_two_modules',
      'install_node_with_config',
      'recipe_include',
    ], 'core/tests/fixtures/recipes');
    // Private method "listAllRecipes".
    $reflection = new \ReflectionMethod('\\Drupal\\Core\\Recipe\\RecipeConfigurator', 'listAllRecipes');
    // Test methods.
    /** @var \Drupal\Core\Recipe\Recipe[] $recipes */
    $recipes = (array) $reflection->invoke($recipe_configurator);
    $recipes_names = array_map(fn(Recipe $recipe) => $recipe->name, $recipes);
    $recipe_extensions = $recipe_configurator->listAllExtensions();
    $expected_recipes_names = [
      'Install two modules',
      'Install node with config',
      'Recipe include',
    ];
    $expected_recipe_extensions = [
      'system',
      'user',
      'filter',
      'field',
      'text',
      'node',
      'dblog',
    ];
    $this->assertEquals($expected_recipes_names, $recipes_names);
    $this->assertEquals($expected_recipe_extensions, $recipe_extensions);
    $this->assertEquals(1, array_count_values($recipes_names)['Install node with config']);
    $this->assertEquals(1, array_count_values($recipe_extensions)['field']);
  }
  
  /**
   * Tests that RecipeConfigurator can load recipes.
   *
   * @testWith ["install_two_modules", "Install two modules"]
   *           ["recipe_include", "Recipe include"]
   *
   * @covers ::getIncludedRecipe
   */
  public function testIncludedRecipeLoader(string $recipe, string $name) : void {
    $recipe = RecipeConfigurator::getIncludedRecipe('core/tests/fixtures/recipes', $recipe);
    $this->assertSame($name, $recipe->name);
  }
  
  /**
   * Tests exception thrown when RecipeConfigurator cannot find a recipe.
   *
   * @testWith ["no_recipe"]
   *           ["does_not_exist"]
   *
   * @covers ::getIncludedRecipe
   */
  public function testIncludedRecipeLoaderException(string $recipe) : void {
    try {
      RecipeConfigurator::getIncludedRecipe('core/tests/fixtures/recipes', $recipe);
      $this->fail('Expected exception not thrown');
    } catch (UnknownRecipeException $e) {
      $this->assertSame($recipe, $e->recipe);
      $this->assertSame('core/tests/fixtures/recipes', $e->searchPath);
      $this->assertSame('Can not find the ' . $recipe . ' recipe, search path: ' . $e->searchPath, $e->getMessage());
    }
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
RecipeConfiguratorTest::testIncludedRecipeLoader public function Tests that RecipeConfigurator can load recipes.
RecipeConfiguratorTest::testIncludedRecipeLoaderException public function Tests exception thrown when RecipeConfigurator cannot find a recipe.
RecipeConfiguratorTest::testRecipeConfigurator public function
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements Deprecated private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements Deprecated protected function Check module requirements for the Drupal use case.
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.

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