diff --git a/core/tests/Drupal/Tests/Component/Scaffold/Fixtures.php b/core/tests/Drupal/Tests/Component/Scaffold/Fixtures.php index d66d7802f9..2a75e795af 100644 --- a/core/tests/Drupal/Tests/Component/Scaffold/Fixtures.php +++ b/core/tests/Drupal/Tests/Component/Scaffold/Fixtures.php @@ -167,7 +167,7 @@ public function sourcePath($project_name, $source) { * @see \Drupal\Component\Scaffold\ManageOptions::getLocationReplacements() */ public function getLocationReplacements() { - $destinationTmpDir = $this->mkTmpDir(); + $destinationTmpDir = $this->mkTmpDir('location-replacements'); $interpolator = new Interpolator(); $interpolator->setData(['web-root' => $destinationTmpDir, 'package-name' => 'fixtures/tmp-destination']); return $interpolator; @@ -237,14 +237,14 @@ public function destinationPath($destination, Interpolator $interpolator = NULL, /** * Generates a path to a temporary location, but do not create the directory. * - * @param string $extraSalt - * Extra characters to throw into the md5 to add to name. + * @param string $prefix + * A prefix for the temporary directory name. * * @return string * Path to temporary directory */ - public function tmpDir($extraSalt = '') { - $tmpDir = sys_get_temp_dir() . '/composer-scaffold-test-' . md5($extraSalt . microtime()); + public function tmpDir($prefix) { + $tmpDir = sys_get_temp_dir() . '/composer-scaffold/' . uniqid($prefix, TRUE); $this->tmpDirs[] = $tmpDir; return $tmpDir; } @@ -252,14 +252,14 @@ public function tmpDir($extraSalt = '') { /** * Creates a temporary directory. * - * @param string $extraSalt - * Extra characters to throw into the md5 to add to name. + * @param string $prefix + * A prefix for the temporary directory name. * * @return string * Path to temporary directory */ - public function mkTmpDir($extraSalt = '') { - $tmpDir = $this->tmpDir($extraSalt); + public function mkTmpDir($prefix) { + $tmpDir = $this->tmpDir($prefix); $filesystem = new Filesystem(); $filesystem->ensureDirectoryExists($tmpDir); return $tmpDir; @@ -342,28 +342,21 @@ public function runScaffold($cwd) { * The Composer command to execute (escaped as required) * @param string $cwd * The current working directory to run the command from. - * @param int $expectedExitCode - * The expected exit code; will throw if a different exit code is returned. * * @return string * Standard output and standard error from the command. */ - public function runComposer($cmd, $cwd, $expectedExitCode = 0) { + public function runComposer($cmd, $cwd) { chdir($cwd); $input = new StringInput($cmd); $output = new BufferedOutput(); $application = new Application(); $application->setAutoExit(FALSE); - try { - $exitCode = $application->run($input, $output); - if ($exitCode != $expectedExitCode) { - print "Command '{$cmd}' - Expected exit code: {$expectedExitCode}, actual exit code: {$exitCode}\n"; - } - } - catch (\Exception $e) { - print "Exception: " . $e->getMessage() . "\n"; - } + $exitCode = $application->run($input, $output); $output = $output->fetch(); + if ($exitCode != 0) { + throw new \Exception("Fixtures::runComposer failed to set up fixtures.\n\nCommand: '{$cmd}'\nExit code: {$exitCode}\nOutput: \n\n$output"); + } return $output; } diff --git a/core/tests/Drupal/Tests/Component/Scaffold/Functional/ManageGitIgnoreTest.php b/core/tests/Drupal/Tests/Component/Scaffold/Functional/ManageGitIgnoreTest.php index c27e3e2fdf..0c24d78cf0 100644 --- a/core/tests/Drupal/Tests/Component/Scaffold/Functional/ManageGitIgnoreTest.php +++ b/core/tests/Drupal/Tests/Component/Scaffold/Functional/ManageGitIgnoreTest.php @@ -169,6 +169,7 @@ public function testUnmanagedGitIgnoreWhenGitNotAvailable() { $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 @@ -179,10 +180,38 @@ public function testUnmanagedGitIgnoreWhenGitNotAvailable() { chmod($unavailableGitPath . '/git', 0755); 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 composer:scaffold', $output, $status); + $expected = <<assertEquals($expected, $status . "\n\n" . implode("\n", $output)); $this->assertFileExists($sut . '/docroot/index.php'); $this->assertFileNotExists($sut . '/docroot/sites/default/.gitignore'); }