Skip to content

Commit c185384

Browse files
richardbporterRichard B. Porter
andauthored
Require Drush 12, Drupal 10 (#103)
* Update README * Require Drush ^12.2, Drupal ^10.1 * Remove README line breaks * Actually require Drupal ^10.1 * Ignore drush dir * Delete drush/drush.yml * Write drush config in test bootstrap * Update test docs * Fix typeError in toggle test * Require Drush ^12.2 * Remove drush.services.yml --------- Co-authored-by: Richard B. Porter <rbp@richardbporter.com>
1 parent afc31a0 commit c185384

File tree

8 files changed

+34
-30
lines changed

8 files changed

+34
-30
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ vendor
66
sut
77
.phpunit.result.cache
88
.DS_Store
9-
phpunit.xml
9+
phpunit.xml
10+
drush

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
Drush commands to interact with multiple Drupal users.
55

66
## Requirements
7-
- Drush ^11.0.5
8-
- Drupal ^9.3 || ^10.0
7+
- Drush ^12.2
8+
- Drupal ^10.1
99

1010
## Installation
11-
Since this is a [site-wide Drush command](https://www.drush.org/latest/commands/#site-wide-drush-commands), it will only be
12-
found when installed in certain directories. It is recommended to update your Composer installers path for drupal-drush
13-
packages to:
11+
Since this is a [site-wide Drush command](https://www.drush.org/latest/commands/#site-wide-commands), it will only be found when installed in certain directories. It is recommended to update your Composer installers path for drupal-drush packages to:
1412
```
1513
"drush/Commands/{$name}": ["type:drupal-drush"]
1614
```
@@ -19,7 +17,7 @@ packages to:
1917
composer require richardbporter/drush-users-commands
2018
```
2119
Note that the directory the package is installed to (UsersCommands) differs from the repository name (drush-users-commands) due to the [installer name property]( https://github.com/composer/installers#custom-install-names).
22-
20+
2321
## Commands
2422

2523
### drush users:list

composer.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"require": {
1414
"php": ">=8.1",
1515
"composer/installers": "^2.1",
16-
"drush/drush": "^11.0.5"
16+
"drush/drush": "^12.2"
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^9.5",
2020
"squizlabs/php_codesniffer": "^3",
21-
"drupal/core-recommended": "^9.3 || ^10.0",
22-
"drupal/core-composer-scaffold": "^9.3 || ^10.0",
21+
"drupal/core-recommended": "^10.1",
22+
"drupal/core-composer-scaffold": "^10.1",
2323
"mglaman/drupal-check": "^1.4",
2424
"symfony/phpunit-bridge": "^6.1",
2525
"drupal/coder": "^8.3"
@@ -30,11 +30,6 @@
3030
}
3131
},
3232
"extra": {
33-
"drush": {
34-
"services": {
35-
"drush.services.yml": "^11.0.5"
36-
}
37-
},
3833
"installer-name": "UsersCommands",
3934
"installer-paths": {
4035
"sut/core": ["type:drupal-core"],

drush.services.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

drush/drush.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Testing
2-
Since this is a [site-wide Drush command](https://docs.drush.org/en/master/commands/#site-wide-drush-commands), it will only be
3-
found when installed in certain directories. Cloning this repository into a directory named "Commands/UsersCommands" is the easiest option, e.g. path/to/Commands/UsersCommands. This directory is included when running tests via the `--include` option in TestBase.php.
2+
Since this is a [site-wide Drush command](https://docs.drush.org/en/latest/commands/#site-wide-commands), it will only be found when installed in certain directories. These directories are hard to mimic in the project structure. Therefore, we leverage the `commands` configuration to load the command in the System Under Test (SUT): https://github.com/drush-ops/drush/blob/12.x/src/Runtime/ServiceManager.php#L127
43

5-
Instead of creating our own SUT, we piggyback off of Drush's by parsing and installing Drush's dev dependencies using wikimedia/composer-merge-plugin. This was a little quicker to set up and allows us to use Unish internals like `$this->webroot` and others. In order to do this, you must install Drush from source, i.e. `composer install --prefer-source`.
4+
Note that this may be deprecated in the future: https://www.drush.org/12.x/commands/#global-commands-discovered-by-configuration
5+
6+
The example-drush-extension project used the `cwd` enviroment variable for this but that seemingly stopped working in 12.x: https://github.com/drush-ops/example-drush-extension/blob/master/sut/drush/drush.yml
7+
8+
The test bootstrap now writes out the absolute path to the command file in the `drush/drush.yml` file. It does this using the `GITHUB_WORKSPACE` environment variable, mostly for convenience in GitHub Actions CI. This variable must be set in `phpunit.xml` when running the tests locally.

tests/ToggleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function setUp() :void {
2222
'db-url' => getenv('DRUPAL_TEST_DB_URL'),
2323
]);
2424

25-
$this->drush('config:set', ['user.settings', 'notify.status_activated', 0]);
26-
$this->drush('config:set', ['user.settings', 'notify.status_blocked', 0]);
25+
$this->drush('config:set', ['user.settings', 'notify.status_activated', '0']);
26+
$this->drush('config:set', ['user.settings', 'notify.status_blocked', '0']);
2727
$this->drush('user:create', ['foo']);
2828
$this->drush('user:create', ['bar']);
2929
$this->drush('user:block', ['bar']);

tests/bootstrap.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,21 @@
55
* Test bootstrap.
66
*/
77

8+
use Symfony\Component\Filesystem\Filesystem;
9+
810
require __DIR__ . '/../vendor/autoload.php';
11+
12+
$fs = new Filesystem();
13+
$path = __DIR__ . '/../drush';
14+
$fs->mkdir($path);
15+
$fs->touch("$path/drush.yml");
16+
$workspace = getenv('GITHUB_WORKSPACE');
17+
18+
$contents = <<<EOD
19+
# Register the command in the SUT.
20+
drush:
21+
commands:
22+
'\Drush\Commands\UsersCommands\UsersCommands': '$workspace/UsersCommands.php'
23+
EOD;
24+
25+
file_put_contents("$path/drush.yml", $contents);

0 commit comments

Comments
 (0)