forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sut
executable file
·47 lines (42 loc) · 1.72 KB
/
sut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env php
<?php
/**
* Run a Drush command against the Site Under Test
*
* @usage sut core-status --verbose
*/
require __DIR__. '/tests/unish.inc';
list($unish_tmp, $unish_sandbox, $unish_drush_dir) = unishGetPaths();
$sut = dirname($unish_sandbox) . '/drush-sut';
$vendor = $sut . '/vendor';
// Get the arguments for the command.
$arguments = $GLOBALS['argv'];
// Shift off argv[0] which contains the name of this script.
array_shift($arguments);
// Add alias if not already specified
if (!empty($arguments) && ($arguments[0][0] != '@')) {
array_unshift($arguments, "@sut.dev");
}
// Make it easy to just call `./sut si -y testing`, or `./sut @sut.stage -y testing`
if (in_array('si', $arguments) || in_array('site-install', $arguments)) {
$subdir = 'dev';
if (in_array('@sut.stage', $arguments)) {
$subdir = 'stage';
}
$db_url = getenv('UNISH_DB_URL') ?: 'mysql:https://root:@127.0.0.1';
$arguments[] = "--db-url=$db_url/unish_$subdir";
$arguments[] = "--sites-subdir=$subdir";
}
/**
* DRUSH_AUTOLOAD_PHP must be provided because Drush is symlinked into the SUT.
* This confuses our autoload.php detection.
*/
$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));
if (unishIsVerbose()) {
fwrite(STDERR, 'Executing: ' . $cmd . "\n");
}
chdir($sut);
$process = proc_open($cmd, [0 => STDIN, 1 => STDOUT, 2 => STDERR], $pipes);
$proc_status = proc_get_status($process);
$exit_code = proc_close($process);
exit($proc_status["running"] ? $exit_code : $proc_status["exitcode"] );