Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / unish.sut.php
1 #!/usr/bin/env php
2 <?php
3
4 /**
5  * This script performs setup and then calls `composer install`. It may not autoload code.
6  */
7
8 require __DIR__ . '/includes/filesystem.inc';
9 require __DIR__ . '/tests/unish.inc';
10
11 list($unish_tmp, $unish_sandbox, $unish_drush_dir) = unishGetPaths();
12 unish_validate();
13 $return = unish_setup_sut($unish_sandbox);
14 exit($return);
15
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');
19     exit(1);
20   }
21 }
22
23 /**
24  * Use Composer to build a Drupal codebase, with this Drush symlinked into /vendor.
25  * @param string $unish_sandbox Path to sandbox.
26  * @return integer
27  *   Exit code.
28  */
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}}'";
42   passthru($cmd);
43
44   $alias_contents = <<<EOT
45 dev:
46   root: $target_dir/web
47   uri: dev
48 stage:
49   root: $target_dir/web
50   uri: stage
51 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);
55
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);
60
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");
65     $return = 1;
66   }
67
68   // Move the sut into place
69   drush_delete_dir($target_dir, TRUE);
70   rename($working_dir, $target_dir);
71
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');
76   }
77
78   return $return;
79 }