function ComposerRequirementTest::testComposerInfoShown

Tests that Composer version and path are listed on the status report.

File

core/modules/package_manager/tests/src/Functional/ComposerRequirementTest.php, line 26

Class

ComposerRequirementTest
Tests that Package Manager shows the Composer version on the status report.

Namespace

Drupal\Tests\package_manager\Functional

Code

public function testComposerInfoShown() : void {
    $config = $this->config('package_manager.settings');
    // Ensure we can locate the Composer executable.
    
    /** @var \PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface $executable_finder */
    $executable_finder = $this->container
        ->get(ExecutableFinderInterface::class);
    $composer_path = $executable_finder->find('composer');
    $composer_version = $this->container
        ->get(ComposerInspector::class)
        ->getVersion();
    // With a valid path to Composer, ensure the status report shows its version
    // number and path.
    $config->set('executables.composer', $composer_path)
        ->save();
    $account = $this->drupalCreateUser([
        'administer site configuration',
    ]);
    $this->drupalLogin($account);
    $this->drupalGet('/admin/reports/status');
    $assert_session = $this->assertSession();
    $assert_session->pageTextContains('Composer version');
    $assert_session->responseContains("{$composer_version} (<code>{$composer_path}</code>)");
    // If the path to Composer is invalid, we should see the error message
    // that gets raised when we try to get its version.
    $config->set('executables.composer', '/path/to/composer')
        ->save();
    $this->getSession()
        ->reload();
    $assert_session->statusCodeEquals(200);
    $assert_session->pageTextContains('Composer was not found. The error message was: Failed to run process: The command "\'/path/to/composer\' \'--format=json\'" failed.');
}

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