function ComposerInspectorTest::testComposerUnavailable

@covers ::validate

File

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

Class

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

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testComposerUnavailable() : void {
  $precondition = $this->prophesize(ComposerIsAvailableInterface::class);
  $mocked_precondition = $precondition->reveal();
  $this->container
    ->set(ComposerIsAvailableInterface::class, $mocked_precondition);
  $message = $this->createComposeStagerMessage("Well, that didn't work.");
  $precondition->assertIsFulfilled(Argument::cetera())
    ->willThrow(new PreconditionException($mocked_precondition, $message))
    ->shouldBeCalledOnce();
  $project_root = $this->container
    ->get(PathLocator::class)
    ->getProjectRoot();
  /** @var \Drupal\package_manager\ComposerInspector $inspector */
  $inspector = $this->container
    ->get(ComposerInspector::class);
  try {
    $inspector->validate($project_root);
    $this->fail('Expected an exception to be thrown, but it was not.');
  } catch (ComposerNotReadyException $e) {
    $this->assertNull($e->workingDir);
    $this->assertSame("Well, that didn't work.", $e->getMessage());
  }
  // Call validate() again to ensure the precondition is called once.
  $this->expectException(ComposerNotReadyException::class);
  $this->expectExceptionMessage("Well, that didn't work.");
  $inspector->validate($project_root);
}

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