forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unish.sut.php
executable file
·79 lines (68 loc) · 2.79 KB
/
unish.sut.php
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env php
<?php
/**
* This script performs setup and then calls `composer install`. It may not autoload code.
*/
require __DIR__ . '/includes/filesystem.inc';
require __DIR__ . '/tests/unish.inc';
list($unish_tmp, $unish_sandbox, $unish_drush_dir) = unishGetPaths();
unish_validate();
$return = unish_setup_sut($unish_sandbox);
exit($return);
function unish_validate() {
if (basename(__DIR__) != 'drush') {
fwrite(STDERR, 'The drush directory must end in /drush in order to run the tests. This is due to the "path" repository in tests/resources/composer.json');
exit(1);
}
}
/**
* Use Composer to build a Drupal codebase, with this Drush symlinked into /vendor.
* @param string $unish_sandbox Path to sandbox.
* @return integer
* Exit code.
*/
function unish_setup_sut($unish_sandbox) {
$working_dir = dirname($unish_sandbox) . DIRECTORY_SEPARATOR . 'build-drush-sut';
$target_dir = dirname($working_dir) . DIRECTORY_SEPARATOR . 'drush-sut';
drush_delete_dir($working_dir, TRUE);
$codebase = __DIR__ . '/tests/resources/codebase';
drush_copy_dir($codebase, $working_dir);
$drush_project_root = escapeshellarg(__DIR__);
$composer_dir = escapeshellarg($working_dir);
// n.b. we expect the COMPOSER environment variable to be set to specify the target composer.json file
// TODO: We could probably use https://github.com/greg-1-anderson/composer-test-scenarios
// with a single composer.json file in tests/resources/codebase/web to manage our test scenarios.
// It might require slight modification to support the path repository below.
$cmd = "composer --working-dir=$composer_dir config repositories.drush '{\"type\":\"path\",\"url\":\"$drush_project_root\",\"options\":{\"symlink\":true}}'";
passthru($cmd);
$alias_contents = <<<EOT
dev:
root: $target_dir/web
uri: dev
stage:
root: $target_dir/web
uri: stage
EOT;
mkdir("$working_dir/drush");
mkdir("$working_dir/drush/sites");
file_put_contents("$working_dir/drush/sites/sut.site.yml", $alias_contents);
$verbose = unishIsVerbose();
$cmd = "composer $verbose install --prefer-dist --no-progress --no-suggest --working-dir " . escapeshellarg($working_dir);
fwrite(STDERR, 'Executing: ' . $cmd . "\n");
exec($cmd, $output, $return);
// If requirements force it to, Composer downloads a second Drush, instead of symlink.
$drush_sut = $working_dir . '/vendor/drush/drush';
if (!is_link($drush_sut)) {
fwrite(STDERR, "Drush not symlinked in the System-Under-Test.\n");
$return = 1;
}
// Move the sut into place
drush_delete_dir($target_dir, TRUE);
rename($working_dir, $target_dir);
// If there is no 'vendor' directory in the Drush home dir, then make
// a symlink from the SUT
if (!is_dir(__DIR__ . '/vendor')) {
symlink("$target_dir/vendor", __DIR__ . '/vendor');
}
return $return;
}