You are here

public function ComposerExecutableValidatorTest::testComposerVersionValidation in Automatic Updates 8.2

Tests validation of various Composer versions.

@dataProvider providerComposerVersionValidation

Parameters

string $reported_version: The version of Composer that `composer --version` should report.

\Drupal\automatic_updates\Validation\ValidationResult[] $expected_results: The expected validation results.

File

tests/src/Kernel/ReadinessValidation/ComposerExecutableValidatorTest.php, line 119

Class

ComposerExecutableValidatorTest
@covers \Drupal\automatic_updates\Validator\ComposerExecutableValidator

Namespace

Drupal\Tests\automatic_updates\Kernel\ReadinessValidation

Code

public function testComposerVersionValidation(string $reported_version, array $expected_results) : void {

  // Mock the output of `composer --version`, will be passed to the validator,
  // which is itself a callback function that gets called repeatedly as
  // Composer produces output.

  /** @var \PhpTuf\ComposerStager\Infrastructure\Process\Runner\ComposerRunnerInterface|\Prophecy\Prophecy\ObjectProphecy $runner */
  $runner = $this
    ->prophesize('\\PhpTuf\\ComposerStager\\Infrastructure\\Process\\Runner\\ComposerRunnerInterface');
  $runner
    ->run([
    '--version',
  ], Argument::type(ComposerExecutableValidator::class))
    ->will(function (array $arguments) use ($reported_version) {

    /** @var \Drupal\automatic_updates\Validator\ComposerExecutableValidator $validator */
    $validator = $arguments[1];

    // Invoke the validator (which, as mentioned, is a callback function),
    // with fake output from `composer --version`. It should try to tease a
    // recognized, supported version number out of this output.
    $validator($validator::OUT, "Composer version {$reported_version}");
  });
  $this->container
    ->set('package_manager.composer_runner', $runner
    ->reveal());

  // If the validator can't find a recognized, supported version of Composer,
  // it should produce errors.
  $this
    ->assertCheckerResultsFromManager($expected_results, TRUE);
}