function ManageGitIgnoreTest::testManageGitIgnore

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

Tests scaffold command correctly manages the .gitignore file.

File

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

Class

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

Namespace

Drupal\Tests\Composer\Plugin\Scaffold\Functional

Code

public function testManageGitIgnore() : 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/autoload.php');
    $this->assertFileDoesNotExist($sut . '/docroot/index.php');
    $this->assertFileDoesNotExist($sut . '/docroot/sites/.gitignore');
    // Run the scaffold command.
    $this->fixtures
        ->runScaffold($sut);
    $this->assertFileExists($sut . '/docroot/autoload.php');
    $this->assertFileExists($sut . '/docroot/index.php');
    $expected = <<<EOT
/build
/.csslintrc
/.editorconfig
/.eslintignore
/.eslintrc.json
/.gitattributes
/.ht.router.php
/autoload.php
/index.php
/robots.txt
/update.php
/web.config
EOT;
    // At this point we should have a .gitignore file, because although we did
    // not explicitly ask for .gitignore tracking, the vendor directory is not
    // tracked, so the default in that instance is to manage .gitignore files.
    $this->assertScaffoldedFile($sut . '/docroot/.gitignore', FALSE, $expected);
    $this->assertScaffoldedFile($sut . '/docroot/sites/.gitignore', FALSE, 'example.settings.local.php');
    $this->assertScaffoldedFile($sut . '/docroot/sites/default/.gitignore', FALSE, 'default.services.yml');
    $expected = <<<EOT
M docroot/.gitignore
?? docroot/sites/.gitignore
?? docroot/sites/default/.gitignore
EOT;
    // Check to see whether there are any untracked files. We expect that
    // only the .gitignore files themselves should be untracked.
    $stdout = $this->mustExec('git status --porcelain', $sut);
    $this->assertEquals(trim($expected), trim($stdout));
}

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