forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unish.sut.php
executable file
·66 lines (58 loc) · 2.11 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
#!/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 . 'drush-sut';
drush_delete_dir($working_dir, TRUE);
$codebase = 'tests/resources/codebase';
drush_copy_dir($codebase, $working_dir);
$composer_json = getenv('COMPOSER') ?: 'composer.json';
foreach ([$composer_json] as $filename) {
$path = $working_dir . "/$filename";
if (file_exists($path)) {
$contents = file_get_contents($path);
$new_contents = replace_token($contents);
file_put_contents($path, $new_contents);
}
}
$verbose = unishIsVerbose();
$cmd = "composer $verbose install --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;
}
return $return;
}
/**
* Replace a token with the /path/to/drush for this install.
*
* @param $contents
*/
function replace_token($contents) {
// @todo Use https://getcomposer.org/doc/03-cli.md#modifying-repositories if it can edit composer.lock too.
return str_replace('%PATH-TO-DRUSH%', __DIR__, $contents);
}