function ComposerInspectorTest::mockComposerRunner

Mocks the Composer runner service to return a particular version string.

Parameters

string|null $reported_version: The version number that `composer --format=json` should return.

Return value

\Prophecy\Prophecy\ObjectProphecy The configurator for the mocked Composer runner.

1 call to ComposerInspectorTest::mockComposerRunner()
ComposerInspectorTest::testVersionCheck in core/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php
@covers ::validate

File

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

Class

ComposerInspectorTest
@coversDefaultClass \Drupal\package_manager\ComposerInspector

Namespace

Drupal\Tests\package_manager\Kernel

Code

private function mockComposerRunner(?string $reported_version) : ObjectProphecy {
    $runner = $this->prophesize(ComposerProcessRunnerInterface::class);
    $pass_version_to_output_callback = function (array $arguments_passed_to_runner) use ($reported_version) : void {
        $command_output = Json::encode([
            'application' => [
                'name' => 'Composer',
                'version' => $reported_version,
            ],
        ]);
        $callback = end($arguments_passed_to_runner);
        assert($callback instanceof OutputCallbackInterface);
        $callback(OutputTypeEnum::OUT, $command_output);
    };
    // We expect the runner to be called with two arguments: an array whose
    // first item is `--format=json`, and an output callback.
    $runner->run(Argument::withEntry(0, '--format=json'), Argument::cetera())
        ->will($pass_version_to_output_callback);
    return $runner;
}

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