Skip to content

Commit 67a7598

Browse files
authored
[#690] Reclassified trait-specific composer dependencies as optional. (#691)
1 parent fd2f627 commit 67a7598

5 files changed

Lines changed: 53 additions & 7 deletions

File tree

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ Run `ahoy lint-docs` to validate the format of the steps.
5151
- **Contains assertions**: Always use `Contains` or `NotContains` (e.g., `xmlAssertElementContains()`, `headerAssertNotContains()`)
5252
- Never use "DoesNot" or "DoNot" patterns - use "Not" prefix directly
5353

54+
## Dependency policy
55+
56+
Keep the `require` section of `composer.json` minimal - it should contain only what **every** consumer needs regardless of which traits they use.
57+
58+
- **`require`**: the framework and browser abstraction that virtually all steps build on - `php`, `behat/behat`, `behat/mink`.
59+
- **`require-dev` + `suggest`**: any package used by only a subset of traits. List it in `require-dev` so this library's own test suite still exercises it, **and** in `suggest` with a message naming the exact trait(s) or step(s) that need it (as `justinrainbow/json-schema` does for `JsonTrait`).
60+
61+
When a new trait needs a package, decide up front: trait-specific packages go in `require-dev` + `suggest`, never in `require`. Demoting a package from `require` to `suggest` later is a breaking change for consumers relying on transitive installation, so batch such demotions into the next major release and document them in [MIGRATION.md](MIGRATION.md).
62+
5463
## Local environment setup
5564

5665
Install [Docker](https://www.docker.com/), [Pygmy](https://github.com/pygmystack/pygmy), [Ahoy](https://github.com/ahoy-cli/ahoy)

MIGRATION.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Migration guide
22

3+
## Optional dependencies moved to `require-dev` and `suggest`
4+
5+
Trait-specific packages are no longer hard `require` dependencies. They now live in `require-dev` (so this library's own test suite still runs) and `suggest`, matching the existing treatment of `justinrainbow/json-schema`. Projects that relied on transitive installation must add the packages they use to their own `composer.json`.
6+
7+
| Package | Add it to your `require-dev` when you use |
8+
| --- | --- |
9+
| `drupal/drupal-extension` | any Drupal trait (`DrevOps\BehatSteps\Drupal\*`) |
10+
| `softcreatr/jsonpath` | `JsonTrait` JSON path steps (`the JSON path ... should ...`) |
11+
12+
`@javascript` scenarios need a JavaScript-capable Mink driver. The steps are driver agnostic, so install **one** of these interchangeable drivers - both run the full `@javascript` suite and both are exercised by this library's CI:
13+
14+
- `lullabot/mink-selenium2-driver` - drives a Selenium/WebDriver server.
15+
- `dmore/behat-chrome-extension` - drives headless Chrome directly over the Chrome DevTools Protocol, with no Selenium server.
16+
17+
`behat/behat` and `behat/mink` remain hard `require` dependencies. For example, a project that uses the Drupal traits and runs JavaScript scenarios with headless Chrome adds:
18+
19+
```bash
20+
composer require --dev drupal/drupal-extension dmore/behat-chrome-extension
21+
```
22+
323
## Unified entity cleanup
424

525
Traits that create Drupal entities now register them in a single shared registry and delete them in reverse creation order through one `entityCleanupAfterScenario` hook, instead of each trait running its own after-scenario cleanup.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ from the community.
114114
composer require --dev drevops/behat-steps:^3
115115
```
116116

117+
### Optional dependencies
118+
119+
To keep installs lean, packages needed by only some traits are declared as `suggest` rather than hard requirements (only `behat/behat` and `behat/mink` are required). Add the ones for the traits you use to your project's `require-dev` - run `composer suggests` to list them:
120+
121+
- **Drupal traits** (`DrevOps\BehatSteps\Drupal\*`) need `drupal/drupal-extension`.
122+
- **`JsonTrait`** needs `softcreatr/jsonpath` for JSON path steps and `justinrainbow/json-schema` for JSON schema steps.
123+
- **`@javascript` scenarios** need a Mink driver - see [JavaScript drivers](#javascript-drivers) below.
124+
117125
## Usage
118126

119127
Add required traits to your

composer.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,42 @@
1919
"require": {
2020
"php": ">=8.2",
2121
"behat/behat": "^3.14",
22-
"behat/mink": ">=1.11",
23-
"dmore/behat-chrome-extension": "^1.4",
24-
"drupal/drupal-extension": "^6.0",
25-
"lullabot/mink-selenium2-driver": "^1.7.4",
26-
"softcreatr/jsonpath": "^0.10 || ^1.0"
22+
"behat/mink": ">=1.11"
2723
},
2824
"require-dev": {
2925
"alexskrypnyk/phpunit-helpers": "^0.15.0",
3026
"cweagans/composer-patches": "^2.0",
3127
"dantleech/gherkin-lint": "^0.2.3",
3228
"dealerdirect/phpcodesniffer-composer-installer": "^1",
29+
"dmore/behat-chrome-extension": "^1.4",
3330
"drevops/behat-phpserver": "^2.1.1",
3431
"drevops/behat-screenshot": "^2.1",
3532
"drevops/phpcs-standard": "^0.7",
3633
"drupal/coder": "^8.3.28",
34+
"drupal/drupal-extension": "^6.0",
3735
"dvdoug/behat-code-coverage": "^5.3.2.1",
3836
"ergebnis/composer-normalize": "^2.47",
3937
"justinrainbow/json-schema": "^6.0",
38+
"lullabot/mink-selenium2-driver": "^1.7.4",
4039
"mglaman/phpstan-drupal": "^2.0.0",
4140
"php-parallel-lint/php-parallel-lint": "^1.4",
4241
"phpcompatibility/php-compatibility": "^9.3.5",
4342
"phpspec/prophecy-phpunit": "^2.3",
4443
"phpstan/extension-installer": "^1.4.3",
4544
"phpstan/phpstan": "^2.0.0",
4645
"phpunit/phpunit": "^11",
47-
"rector/rector": "^2.0"
46+
"rector/rector": "^2.0",
47+
"softcreatr/jsonpath": "^0.10 || ^1.0"
4848
},
4949
"conflict": {
5050
"drupal/drupal-extension": "<6"
5151
},
5252
"suggest": {
53-
"justinrainbow/json-schema": "Required by JsonTrait for JSON Schema validation steps ('the response should match the JSON schema ...')."
53+
"dmore/behat-chrome-extension": "JavaScript driver for @javascript scenarios: drives headless Chrome directly over the Chrome DevTools Protocol (selenium-less). Interchangeable with lullabot/mink-selenium2-driver - install one.",
54+
"drupal/drupal-extension": "Required by all Drupal step traits (src/Drupal/*), which build on the Drupal Extension RawDrupalContext and Drupal driver.",
55+
"justinrainbow/json-schema": "Required by JsonTrait for JSON Schema validation steps ('the response should match the JSON schema ...').",
56+
"lullabot/mink-selenium2-driver": "JavaScript driver for @javascript scenarios: drives a Selenium/WebDriver server. Interchangeable with dmore/behat-chrome-extension - install one.",
57+
"softcreatr/jsonpath": "Required by JsonTrait for JSON path assertion steps ('the JSON path ... should ...')."
5458
},
5559
"autoload": {
5660
"psr-4": {

scripts/provision.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ $fixture = json_decode(file_get_contents("/app/build/composer.json"), true);
3333
// Cherry-pick the required properties from the base composer.json.
3434
$package_filtered["require-dev"] = $package["require"];
3535
36+
// Trait-specific runtime dependencies live in "require-dev" + "suggest" rather
37+
// than "require", so the fixture site - which exercises every trait - must pull
38+
// each suggested package back in to run the full Behat suite.
39+
$package_filtered["require-dev"] = array_merge($package_filtered["require-dev"], array_intersect_key($package["require-dev"], $package["suggest"]));
40+
3641
// Deps required to run Behat tests.
3742
$package_filtered["require-dev"] = array_merge($package_filtered["require-dev"], array_filter($package["require-dev"], function ($ver, $name) {
3843
return in_array($name, [

0 commit comments

Comments
 (0)