Skip to content

Commit eed106a

Browse files
Improve testability of the startup (runtime / preflight) code (#3809)
1 parent bc4ca9b commit eed106a

36 files changed

+753
-293
lines changed

.circleci/config.yml

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,35 @@ defaults: &defaults
1010

1111
version: 2
1212
jobs:
13-
build:
13+
# Code style test:
14+
# FAIL if code does not conform to PSR-2 conventions
15+
# PASS otherwise
16+
code_style:
17+
<<: *defaults
18+
docker:
19+
- image: wodby/php:7.1
20+
steps:
21+
- checkout
22+
- run: cp .docker/zz-php.ini /usr/local/etc/php/conf.d/
23+
- run: composer install
24+
- run: composer cs
25+
26+
# Mergable test:
27+
# FAIL if merging test branch with master produces conflicts
28+
# PASS if the test branch is out of date, but mergable without conflicts
29+
check_mergable:
30+
<<: *defaults
31+
docker:
32+
- image: wodby/php:7.1
33+
steps:
34+
- checkout
35+
- run: git config --global user.email "[email protected]"
36+
- run: git config --global user.name "Drush Merge Test Bot"
37+
- run: git merge -q -m 'Merge check' origin/master
38+
39+
# PHP 7.1 test:
40+
# Checks the most common configuration.
41+
test_71:
1442
<<: *defaults
1543
docker:
1644
- image: wodby/php:7.1
@@ -23,9 +51,12 @@ jobs:
2351
- run: cp .docker/zz-php.ini /usr/local/etc/php/conf.d/
2452
- run: composer install
2553
- run: $HOME/drush/.circleci/patch.sh
54+
- run: composer lint
2655
- run: composer functional
2756

28-
build_highest:
57+
# PHP 7.2 test with HIGHEST dependencies:
58+
# Determines whether a newer version of a dependency has broken Drush.
59+
test_72_highest:
2960
<<: *defaults
3061
docker:
3162
- image: wodby/php:7.2
@@ -39,10 +70,16 @@ jobs:
3970
- run: composer remove --dev webflo/drupal-core-strict --no-update
4071
- run: composer require --dev drupal/core:8.7.x-dev --no-update
4172
- run: composer config platform.php 7.2
42-
- run: composer install
73+
- run: composer update
74+
- run: composer lint
4375
- run: composer functional
4476

45-
build_56:
77+
# PHP 5.6 test with LOWEST dependencies:
78+
# Determines whether any code introduced in this branch uses language
79+
# features not available in PHP 5.6, or whether there are any API calls
80+
# to dependency features not available in the lowest version listed
81+
# for a dependency in our composer.json file.
82+
test_56_lowest:
4683
<<: *defaults
4784
docker:
4885
- image: wodby/php:5.6
@@ -53,14 +90,41 @@ jobs:
5390
steps:
5491
- checkout
5592
- run: cp .docker/zz-php.ini /usr/local/etc/php/conf.d/
56-
- run: .scenarios.lock/install php5
93+
- run: .scenarios.lock/install php5 lowest
5794
- run: $HOME/drush/.circleci/patch.sh
95+
- run: composer lint
5896
- run: composer functional
5997

6098
workflows:
6199
version: 2
62-
build_test:
100+
# Drush test jobs:
101+
# - If the mergable test fails, then skip all of the other tests
102+
# (except code style)
103+
# - If code style check fails, then run only the LOWEST test and skip
104+
# all of the others.
105+
# - If both the code style and mergable checks pass, then run the
106+
# standard and LOWEST tests.
107+
drush:
63108
jobs:
64-
- build
65-
- build_highest
66-
- build_56
109+
- code_style
110+
- check_mergable
111+
- test_71:
112+
requires:
113+
- check_mergable
114+
- code_style
115+
- test_56_lowest:
116+
requires:
117+
- check_mergable
118+
# Drush scheduled jobs:
119+
# - Run the HIGHEST tests daily at the stroke of midnight UTC
120+
scheduled:
121+
triggers:
122+
- schedule:
123+
cron: "0 0 * * *"
124+
filters:
125+
branches:
126+
only:
127+
- master
128+
jobs:
129+
- test_72_highest
130+

.docker/zz-php.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[PHP]
22
variables_order = GPCS
33
error_reporting = E_ALL & ~E_DEPRECATED
4-
date.timezone = "UTC"
4+
date.timezone = "UTC"
5+
sendmail_path = "true"

.scenarios.lock/php5/composer.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"consolidation/output-formatters": "^3.3.1",
6565
"consolidation/robo": "^1.1.5",
6666
"consolidation/site-alias": "^1.1.6|^2",
67-
"consolidation/site-process": "^0.1.13",
67+
"consolidation/site-process": "^0.1.18",
6868
"grasmash/yaml-expander": "^1.1.1",
6969
"league/container": "~2",
7070
"psr/log": "~1.0",
@@ -125,18 +125,17 @@
125125
],
126126
"test": [
127127
"@lint",
128-
"@unit",
129-
"@integration",
130-
"@functional",
128+
"@phpunit",
131129
"@cs"
132130
],
133131
"api": "PATH=$HOME/bin:$PATH sami.phar --ansi update sami-config.php",
134132
"sami-install": "mkdir -p $HOME/bin && curl --output $HOME/bin/sami.phar http://get.sensiolabs.org/sami.phar && chmod +x $HOME/bin/sami.phar",
135133
"sut": "./drush --uri=dev",
136134
"sut:si": "./drush site:install testing --uri=dev --sites-subdir=dev --db-url=${UNISH_DB_URL:-mysql://root:password@mariadb}/unish_dev -v",
137-
"unit": "phpunit --colors=always --configuration tests --testsuite unit",
138-
"integration": "phpunit --colors=always --configuration tests --testsuite integration",
139-
"functional": "phpunit --colors=always --configuration tests --testsuite functional"
135+
"phpunit": "php -d sendmail_path='true' vendor/bin/phpunit --colors=always --configuration tests",
136+
"unit": "composer phpunit -- --testsuite unit",
137+
"integration": "composer phpunit -- --testsuite integration",
138+
"functional": "composer phpunit -- --testsuite functional"
140139
},
141140
"extra": {
142141
"installer-paths": {

.scenarios.lock/php5/composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ before_script:
5050

5151
script:
5252
- composer unit
53-
# - composer integration
53+
- composer integration
5454

5555
after_success:
5656
# Publish updated API documentation on every push to the master branch

composer.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"consolidation/output-formatters": "^3.3.1",
4141
"consolidation/robo": "^1.1.5",
4242
"consolidation/site-alias": "^1.1.6|^2",
43-
"consolidation/site-process": "^0.1.13",
43+
"consolidation/site-process": "^0.1.18",
4444
"grasmash/yaml-expander": "^1.1.1",
4545
"league/container": "~2",
4646
"psr/log": "~1.0",
@@ -98,18 +98,17 @@
9898
],
9999
"test": [
100100
"@lint",
101-
"@unit",
102-
"@integration",
103-
"@functional",
101+
"@phpunit",
104102
"@cs"
105103
],
106104
"api": "PATH=$HOME/bin:$PATH sami.phar --ansi update sami-config.php",
107105
"sami-install": "mkdir -p $HOME/bin && curl --output $HOME/bin/sami.phar http://get.sensiolabs.org/sami.phar && chmod +x $HOME/bin/sami.phar",
108106
"sut": "./drush --uri=dev",
109107
"sut:si": "./drush site:install testing --uri=dev --sites-subdir=dev --db-url=${UNISH_DB_URL:-mysql://root:password@mariadb}/unish_dev -v",
110-
"unit": "phpunit --colors=always --configuration tests --testsuite unit",
111-
"integration": "phpunit --colors=always --configuration tests --testsuite integration",
112-
"functional": "phpunit --colors=always --configuration tests --testsuite functional"
108+
"phpunit": "php -d sendmail_path='true' vendor/bin/phpunit --colors=always --configuration tests",
109+
"unit": "composer phpunit -- --testsuite unit",
110+
"integration": "composer phpunit -- --testsuite integration",
111+
"functional": "composer phpunit -- --testsuite functional"
113112
},
114113
"extra": {
115114
"installer-paths": {

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drush.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Drush\Config\Environment;
55
use Drush\Preflight\Preflight;
66
use Drush\Runtime\Runtime;
7+
use Drush\Runtime\DependencyInjection;
78
use Webmozart\PathUtil\Path;
89

910
/**
@@ -62,7 +63,9 @@
6263

6364
// Preflight and run
6465
$preflight = new Preflight($environment);
65-
$runtime = new Runtime($preflight);
66+
$di = new DependencyInjection();
67+
$di->desiredHandlers(['errorHandler', 'shutdownHandler']);
68+
$runtime = new Runtime($preflight, $di);
6669
$status_code = $runtime->run($_SERVER['argv']);
6770

6871
exit($status_code);

includes/environment.inc

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,6 @@ use Drush\Drush;
1414
use Drush\Log\LogLevel;
1515
use Webmozart\PathUtil\Path;
1616

17-
/**
18-
* Log PHP errors to the Drush log. This is in effect until Drupal's error
19-
* handler takes over.
20-
*/
21-
function drush_error_handler($errno, $message, $filename, $line) {
22-
// E_DEPRECATED was added in PHP 5.3. Drupal 6 will not fix all the
23-
// deprecated errors, but suppresses them. So we suppress them as well.
24-
if (defined('E_DEPRECATED')) {
25-
$errno = $errno & ~E_DEPRECATED;
26-
}
27-
28-
// "error_reporting" is usually set in php.ini, but may be changed by
29-
// drush_errors_on() and drush_errors_off().
30-
if ($errno & error_reporting()) {
31-
// By default we log notices.
32-
$type = Drush::config()->get('runtime.php.notices', LogLevel::INFO);
33-
$halt_on_error = Drush::config()->get('runtime.php.halt-on-error', (drush_drupal_major_version() != 6));
34-
35-
// Bitmask value that constitutes an error needing to be logged.
36-
$error = E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR;
37-
if ($errno & $error) {
38-
$type = 'error';
39-
}
40-
41-
// Bitmask value that constitutes a warning being logged.
42-
$warning = E_WARNING | E_CORE_WARNING | E_COMPILE_WARNING | E_USER_WARNING;
43-
if ($errno & $warning) {
44-
$type = LogLevel::WARNING;
45-
}
46-
47-
Drush::logger()->log($type, $message . ' ' . basename($filename) . ':' . $line);
48-
49-
if ($errno == E_RECOVERABLE_ERROR && $halt_on_error) {
50-
Drush::logger()->error(dt('E_RECOVERABLE_ERROR encountered; aborting. To ignore recoverable errors, run again with --no-halt-on-error'));
51-
exit(DRUSH_APPLICATION_ERROR);
52-
}
53-
54-
return TRUE;
55-
}
56-
}
57-
5817
/**
5918
* Converts a Windows path (dir1\dir2\dir3) into a Unix path (dir1/dir2/dir3).
6019
* Also converts a cygwin "drive emulation" path (/cygdrive/c/dir1) into a

includes/preflight.inc

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,6 @@ function drush_main() {
1818
require dirname(__DIR__) . '/drush.php';
1919
}
2020

21-
/**
22-
* If the command is being executed with the --backend option, the script
23-
* will return a json string containing the options and log information
24-
* used by the script.
25-
*
26-
* The command will exit with '0' if it was successfully executed, and the
27-
* result of drush_get_error() if it wasn't.
28-
*/
29-
function drush_shutdown() {
30-
// Avoid doing anything if our container has not been initialized yet.
31-
if (!Drush::hasContainer()) {
32-
return;
33-
}
34-
35-
if (!Drush::config()->get(Runtime::DRUSH_RUNTIME_COMPLETED_NAMESPACE)) {
36-
Drush::logger()->warning('Drush command terminated abnormally. Check for an exit() in your Drupal site.');
37-
}
38-
39-
if (Drush::backend()) {
40-
drush_backend_output();
41-
}
42-
43-
// This way drush_return_status() will always be the last shutdown function (unless other shutdown functions register shutdown functions...)
44-
// and won't prevent other registered shutdown functions (IE from numerous cron methods) from running by calling exit() before they get a chance.
45-
register_shutdown_function('drush_return_status');
46-
}
47-
4821
/**
4922
* Shutdown function to save code coverage data.
5023
*/
@@ -80,10 +53,3 @@ function drush_coverage_shutdown() {
8053
file_put_contents($file_name, serialize($data));
8154
}
8255
}
83-
84-
/**
85-
* @deprecated. This function will be removed in Drush 10. Throw an exception to indicate an error.
86-
*/
87-
function drush_return_status() {
88-
exit(Runtime::exitCode());
89-
}

0 commit comments

Comments
 (0)