function UnpackRecipeTest::testUnpackCommandOnDevRecipe

Tests unpacking a recipe in require-dev using drupal:recipe-unpack.

File

core/tests/Drupal/Tests/Composer/Plugin/Unpack/Functional/UnpackRecipeTest.php, line 314

Class

UnpackRecipeTest
Tests recipe unpacking.

Namespace

Drupal\Tests\Composer\Plugin\Unpack\Functional

Code

public function testUnpackCommandOnDevRecipe() : void {
  $root_project_path = $this->fixturesDir . '/composer-root';
  // Run composer install and confirm the composer.lock was created.
  $this->runComposer('install');
  // Disable automatic unpacking, which is the default behavior.
  $this->runComposer('config --merge --json extra.drupal-recipe-unpack.on-require false');
  $this->runComposer('require fixtures/recipe-b');
  // Install a recipe and check it is not unpacked.
  $this->runComposer('require --dev fixtures/recipe-a');
  $root_composer_json = $this->getFileContents($root_project_path . '/composer.json');
  $this->assertArrayHasKey('fixtures/recipe-a', $root_composer_json['require-dev']);
  $this->assertArrayHasKey('fixtures/recipe-b', $root_composer_json['require']);
  $error_output = '';
  $stdout = $this->runComposer('drupal:recipe-unpack fixtures/recipe-a', error_output: $error_output);
  $this->assertStringContainsString("fixtures/recipe-a is present in the require-dev key. Unpacking will move the recipe's dependencies to the require key.", $error_output);
  $root_composer_json = $this->getFileContents($root_project_path . '/composer.json');
  // Ensure recipe A's dependencies are moved to require.
  $this->doTestRecipeAUnpacked($root_project_path, $stdout);
  // Ensure recipe B's dependencies are in require and the recipe has been
  // unpacked.
  $this->assertArrayNotHasKey('fixtures/recipe-b', $root_composer_json['require']);
  $this->assertArrayHasKey('fixtures/module-a', $root_composer_json['require']);
  $this->assertArrayHasKey('fixtures/theme-a', $root_composer_json['require']);
  // Ensure installed.json and installed.php are correct.
  $installed_json = $this->getFileContents($root_project_path . '/vendor/composer/installed.json');
  $installed_packages = array_column($installed_json['packages'], 'name');
  $this->assertContains('fixtures/module-b', $installed_packages);
  $this->assertNotContains('fixtures/recipe-a', $installed_packages);
  $this->assertSame([], $installed_json['dev-package-names']);
  $installed_php = (include_once $root_project_path . '/vendor/composer/installed.php');
  $this->assertArrayHasKey('fixtures/module-b', $installed_php['versions']);
  $this->assertFalse($installed_php['versions']['fixtures/module-b']['dev_requirement']);
  $this->assertArrayNotHasKey('fixtures/recipe-a', $installed_php['versions']);
}

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