You are here

public function ManageGitIgnoreTest::testUnmanagedGitIgnoreWhenGitNotAvailable in Drupal 8

Same name and namespace in other branches
  1. 9 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 191

Class

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

Namespace

Drupal\Tests\Composer\Plugin\Scaffold\Functional

Code

public function testUnmanagedGitIgnoreWhenGitNotAvailable() {

  // 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
    ->assertFileNotExists($sut . '/docroot/sites/default/.gitignore');
  $this
    ->assertFileNotExists($sut . '/docroot/index.php');
  $this
    ->assertFileNotExists($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 = $this->fixtures
    ->binFixtureDir('disable-git-bin');
  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 = [];
  exec('composer drupal:scaffold', $output, $status);
  putenv('PATH=' . $oldPath . ':' . getenv('PATH'));
  $expected = <<<EOT
0

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
  - Copy [web-root]/web.config from assets/web.config
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
    ->assertEquals($expected, $status . "\n\n" . implode("\n", $output));
  $this
    ->assertFileExists($sut . '/docroot/index.php');
  $this
    ->assertFileNotExists($sut . '/docroot/sites/default/.gitignore');
}