function UnpackRecipeTest::testAutomaticUnpack

Tests the dependencies unpack on install.

File

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

Class

UnpackRecipeTest
Tests recipe unpacking.

Namespace

Drupal\Tests\Composer\Plugin\Unpack\Functional

Code

public function testAutomaticUnpack() : void {
  $root_project_path = $this->fixturesDir . '/composer-root';
  copy($root_project_path . '/composer.json', $root_project_path . '/composer.json.original');
  // Run composer install and confirm the composer.lock was created.
  $this->runComposer('install');
  // Install a module in require-dev that should be moved to require
  // by the unpacker.
  $this->runComposer('require --dev fixtures/module-a:^1.0');
  // Ensure we have added the dependency to require-dev.
  $root_composer_json = $this->getFileContents($root_project_path . '/composer.json');
  $this->assertArrayHasKey('fixtures/module-a', $root_composer_json['require-dev']);
  // Install a recipe and unpack it.
  $stdout = $this->runComposer('require fixtures/recipe-a');
  $this->doTestRecipeAUnpacked($root_project_path, $stdout);
  $root_composer_json = $this->getFileContents($root_project_path . '/composer.json');
  // The more specific constraint should have been used.
  $this->assertSame("^1.0", $root_composer_json['require']['fixtures/module-a']);
  // Copy old composer.json back over and require recipe again to ensure it
  // is still unpacked. This tests that unpacking does not rely on composer
  // package events.
  unlink($root_project_path . '/composer.json');
  copy($root_project_path . '/composer.json.original', $root_project_path . '/composer.json');
  $stdout = $this->runComposer('require fixtures/recipe-a');
  $this->doTestRecipeAUnpacked($root_project_path, $stdout);
}

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