function ComposerInspectorTest::testComposerFilesDoNotExist

Tests what happens when composer.json or composer.lock are missing.

@covers ::validate

@testWith ["composer.json"]
["composer.lock"]

Parameters

string $filename: The filename to delete, which should cause validate() to raise an error.

File

core/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php, line 200

Class

ComposerInspectorTest
@coversDefaultClass \Drupal\package_manager\ComposerInspector[[api-linebreak]]

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testComposerFilesDoNotExist(string $filename) : void {
  $project_root = $this->container
    ->get(PathLocator::class)
    ->getProjectRoot();
  $file_path = $project_root . '/' . $filename;
  unlink($file_path);
  /** @var \Drupal\package_manager\ComposerInspector $inspector */
  $inspector = $this->container
    ->get(ComposerInspector::class);
  try {
    $inspector->validate($project_root);
  } catch (ComposerNotReadyException $e) {
    $this->assertSame($project_root, $e->workingDir);
    $this->assertStringContainsString("{$filename} not found", $e->getMessage());
  }
}

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