5 * Run a Drush command against the Site Under Test
7 * @usage sut core-status --verbose
10 require __DIR__. '/tests/unish.inc';
11 list($unish_tmp, $unish_sandbox, $unish_drush_dir) = unishGetPaths();
12 $sut = dirname($unish_sandbox) . '/drush-sut';
13 $vendor = $sut . '/vendor';
15 // Get the arguments for the command.
16 $arguments = $GLOBALS['argv'];
17 // Shift off argv[0] which contains the name of this script.
18 array_shift($arguments);
19 // Add alias if not already specified
20 if (!empty($arguments) && ($arguments[0][0] != '@')) {
21 array_unshift($arguments, "@sut.dev");
24 // Make it easy to just call `./sut si -y testing`, or `./sut @sut.stage -y testing`
25 if (in_array('si', $arguments) || in_array('site-install', $arguments)) {
27 if (in_array('@sut.stage', $arguments)) {
30 $db_url = getenv('UNISH_DB_URL') ?: 'mysql://root:@127.0.0.1';
31 $arguments[] = "--db-url=$db_url/unish_$subdir";
32 $arguments[] = "--sites-subdir=$subdir";
36 * DRUSH_AUTOLOAD_PHP must be provided because Drush is symlinked into the SUT.
37 * This confuses our autoload.php detection.
39 $cmd = "DRUSH_AUTOLOAD_PHP=$vendor/autoload.php ETC_PREFIX=$unish_sandbox SHARE_PREFIX=$unish_sandbox TEMP=$unish_sandbox/tmp HOME=$unish_sandbox/home " . escapeshellarg($vendor . '/bin/drush') . ' ' . implode(' ', array_map(function ($item) { return escapeshellarg($item); }, $arguments));
40 if (unishIsVerbose()) {
41 fwrite(STDERR, 'Executing: ' . $cmd . "\n");
44 $process = proc_open($cmd, [0 => STDIN, 1 => STDOUT, 2 => STDERR], $pipes);
45 $proc_status = proc_get_status($process);
46 $exit_code = proc_close($process);
47 exit($proc_status["running"] ? $exit_code : $proc_status["exitcode"] );