function ExecTrait::mustExec

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

Runs an arbitrary command.

Parameters

string $cmd: The command to execute (escaped as required)

string $cwd: The current working directory to run the command from.

array $env: Environment variables to define for the subprocess.

Return value

string Standard output from the command

8 calls to ExecTrait::mustExec()
ComposerHookTest::testComposerHooks in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ComposerHookTest.php
Tests to see if scaffold operation runs at the correct times.
ComposerHookTest::testScaffoldEvents in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ComposerHookTest.php
Tests to see if scaffold events are dispatched and picked up by the plugin.
ComposerHookTest::testScaffoldMessagesDoNotPrintTwice in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ComposerHookTest.php
Tests to see if scaffold messages are omitted when running scaffold twice.
ManageGitIgnoreTest::createSutWithGit in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php
Creates a system-under-test and initialize a git repository for it.
ManageGitIgnoreTest::testManageGitIgnore in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php
Tests scaffold command correctly manages the .gitignore file.

... See full list

File

core/tests/Drupal/Tests/Composer/Plugin/Scaffold/ExecTrait.php, line 27

Class

ExecTrait
Convenience class for creating fixtures.

Namespace

Drupal\Tests\Composer\Plugin\Scaffold

Code

protected function mustExec($cmd, $cwd, array $env = []) : string {
    $process = Process::fromShellCommandline($cmd, $cwd, $env + [
        'PATH' => getenv('PATH'),
        'HOME' => getenv('HOME'),
    ]);
    $process->setTimeout(300)
        ->setIdleTimeout(300)
        ->run();
    $exitCode = $process->getExitCode();
    if (0 != $exitCode) {
        throw new \RuntimeException("Exit code: {$exitCode}\n\n" . $process->getErrorOutput() . "\n\n" . $process->getOutput());
    }
    return $process->getOutput();
}

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