function ManageGitIgnoreTest::testUnmanagedGitIgnoreWhenGitNotAvailable

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php \Drupal\Tests\Composer\Plugin\Scaffold\Functional\ManageGitIgnoreTest::testUnmanagedGitIgnoreWhenGitNotAvailable()
  2. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php \Drupal\Tests\Composer\Plugin\Scaffold\Functional\ManageGitIgnoreTest::testUnmanagedGitIgnoreWhenGitNotAvailable()
  3. 10 core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php \Drupal\Tests\Composer\Plugin\Scaffold\Functional\ManageGitIgnoreTest::testUnmanagedGitIgnoreWhenGitNotAvailable()

Tests scaffold command disables .gitignore management when git not present.

The scaffold operation should still succeed if there is no 'git' executable.

File

core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php, line 190

Class

ManageGitIgnoreTest
Tests to see whether .gitignore files are correctly managed.

Namespace

Drupal\Tests\Composer\Plugin\Scaffold\Functional

Code

public function testUnmanagedGitIgnoreWhenGitNotAvailable() : void {
    // Note that the drupal-composer-drupal-project fixture does not have any
    // configuration settings related to .gitignore management.
    $sut = $this->createSutWithGit('drupal-composer-drupal-project');
    $this->assertFileDoesNotExist($sut . '/docroot/sites/default/.gitignore');
    $this->assertFileDoesNotExist($sut . '/docroot/index.php');
    $this->assertFileDoesNotExist($sut . '/docroot/sites/.gitignore');
    // Confirm that 'git' is available (n.b. if it were not, createSutWithGit()
    // would fail).
    $output = [];
    exec('git --help', $output, $status);
    $this->assertEquals(0, $status);
    // Modify our $PATH so that it begins with a path that contains an
    // executable script named 'git' that always exits with 127, as if git were
    // not found. Note that we run our tests using process isolation, so we do
    // not need to restore the PATH when we are done.
    $unavailableGitPath = $sut . '/bin';
    mkdir($unavailableGitPath);
    $bash = <<<SH
#!/bin/bash
exit 127

SH;
    file_put_contents($unavailableGitPath . '/git', $bash);
    chmod($unavailableGitPath . '/git', 0755);
    $oldPath = getenv('PATH');
    putenv('PATH=' . $unavailableGitPath . ':' . getenv('PATH'));
    // Confirm that 'git' is no longer available.
    $output = [];
    exec('git --help', $output, $status);
    $this->assertEquals(127, $status);
    // Run the scaffold command.
    $output = $this->mustExec('composer drupal:scaffold 2>&1', NULL);
    putenv('PATH=' . $oldPath . ':' . getenv('PATH'));
    $expected = <<<EOT
Scaffolding files for fixtures/drupal-assets-fixture:
  - Copy [web-root]/.csslintrc from assets/.csslintrc
  - Copy [web-root]/.editorconfig from assets/.editorconfig
  - Copy [web-root]/.eslintignore from assets/.eslintignore
  - Copy [web-root]/.eslintrc.json from assets/.eslintrc.json
  - Copy [web-root]/.gitattributes from assets/.gitattributes
  - Copy [web-root]/.ht.router.php from assets/.ht.router.php
  - Skip [web-root]/.htaccess: overridden in fixtures/drupal-composer-drupal-project
  - Copy [web-root]/sites/default/default.services.yml from assets/default.services.yml
  - Skip [web-root]/sites/default/default.settings.php: overridden in fixtures/scaffold-override-fixture
  - Copy [web-root]/sites/example.settings.local.php from assets/example.settings.local.php
  - Copy [web-root]/sites/example.sites.php from assets/example.sites.php
  - Copy [web-root]/index.php from assets/index.php
  - Skip [web-root]/robots.txt: overridden in fixtures/drupal-composer-drupal-project
  - Copy [web-root]/update.php from assets/update.php
Scaffolding files for fixtures/scaffold-override-fixture:
  - Copy [web-root]/sites/default/default.settings.php from assets/override-settings.php
Scaffolding files for fixtures/drupal-composer-drupal-project:
  - Skip [web-root]/.htaccess: disabled
  - Copy [web-root]/robots.txt from assets/robots-default.txt

EOT;
    $this->assertStringContainsString($expected, $output);
    $this->assertFileExists($sut . '/docroot/index.php');
    $this->assertFileDoesNotExist($sut . '/docroot/sites/default/.gitignore');
}

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