5 * This script performs setup and then calls `composer install`. It may not autoload code.
8 require __DIR__ . '/includes/filesystem.inc';
9 require __DIR__ . '/tests/unish.inc';
11 list($unish_tmp, $unish_sandbox, $unish_drush_dir) = unishGetPaths();
13 $return = unish_setup_sut($unish_sandbox);
16 function unish_validate() {
17 if (basename(__DIR__) != 'drush') {
18 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');
24 * Use Composer to build a Drupal codebase, with this Drush symlinked into /vendor.
25 * @param string $unish_sandbox Path to sandbox.
29 function unish_setup_sut($unish_sandbox) {
30 $working_dir = dirname($unish_sandbox) . DIRECTORY_SEPARATOR . 'build-drush-sut';
31 $target_dir = dirname($working_dir) . DIRECTORY_SEPARATOR . 'drush-sut';
32 drush_delete_dir($working_dir, TRUE);
33 $codebase = __DIR__ . '/tests/resources/codebase';
34 drush_copy_dir($codebase, $working_dir);
35 $drush_project_root = escapeshellarg(__DIR__);
36 $composer_dir = escapeshellarg($working_dir);
37 // n.b. we expect the COMPOSER environment variable to be set to specify the target composer.json file
38 // TODO: We could probably use https://github.com/greg-1-anderson/composer-test-scenarios
39 // with a single composer.json file in tests/resources/codebase/web to manage our test scenarios.
40 // It might require slight modification to support the path repository below.
41 $cmd = "composer --working-dir=$composer_dir config repositories.drush '{\"type\":\"path\",\"url\":\"$drush_project_root\",\"options\":{\"symlink\":true}}'";
44 $alias_contents = <<<EOT
52 mkdir("$working_dir/drush");
53 mkdir("$working_dir/drush/sites");
54 file_put_contents("$working_dir/drush/sites/sut.site.yml", $alias_contents);
56 $verbose = unishIsVerbose();
57 $cmd = "composer $verbose install --prefer-dist --no-progress --no-suggest --working-dir " . escapeshellarg($working_dir);
58 fwrite(STDERR, 'Executing: ' . $cmd . "\n");
59 exec($cmd, $output, $return);
61 // If requirements force it to, Composer downloads a second Drush, instead of symlink.
62 $drush_sut = $working_dir . '/vendor/drush/drush';
63 if (!is_link($drush_sut)) {
64 fwrite(STDERR, "Drush not symlinked in the System-Under-Test.\n");
68 // Move the sut into place
69 drush_delete_dir($target_dir, TRUE);
70 rename($working_dir, $target_dir);
72 // If there is no 'vendor' directory in the Drush home dir, then make
73 // a symlink from the SUT
74 if (!is_dir(__DIR__ . '/vendor')) {
75 symlink("$target_dir/vendor", __DIR__ . '/vendor');