function RecipeFinderTest::testComposerRecipeDirectory

Tests that the Composer recipe directory is read correctly.

File

core/tests/Drupal/KernelTests/Core/Recipe/RecipeFinderTest.php, line 125

Class

RecipeFinderTest
Tests the recipe finder.

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testComposerRecipeDirectory() : void {
  $temp_dir = FileSystem::getOsTemporaryDirectory() . '/test';
  mkdir($temp_dir . '/recipes/test', recursive: TRUE);
  $contents = Json::encode([
    'extra' => [
      'installer-paths' => [
        'recipes/{$name}' => [
          'type:' . Recipe::COMPOSER_PROJECT_TYPE,
        ],
      ],
    ],
  ]);
  file_put_contents($temp_dir . '/composer.json', $contents);
  $this->assertSame($temp_dir . '/recipes/{$name}', Finder::getComposerRecipesDirectory($temp_dir));
  // The project root is now statically cached, so if we put a recipe in
  // there, it should be discovered.
  file_put_contents($temp_dir . '/recipes/test/recipe.yml', 'name: Test!');
  $names = array_column(iterator_to_array(new Finder()), 'name');
  $this->assertContains('Test!', $names);
  // Core recipes should be discovered too, by default.
  $this->assertContains('Administrator role', $names);
  (new SymfonyFilesystem())->remove($temp_dir);
}

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