[#571] Added ConfigOverrideTrait to disable Drupal config overrides via tags.#626
[#571] Added ConfigOverrideTrait to disable Drupal config overrides via tags.#626AlexSkrypnyk merged 3 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdded a new Drupal Behat trait Changes
Sequence Diagram(s)sequenceDiagram
participant Behat as Behat Test
participant Context as Test Context<br/>(ConfigOverrideTrait)
participant Mink as Mink Driver
participant SUT as System Under Test<br/>(Drupal)
Behat->>Context: BeforeScenario — collect `@disable-config-override:*` tags
Note over Context: store unique config names
Behat->>Context: BeforeStep — emit signals
alt skip tags present
Note over Context: skip emission for this scenario/step
else
Context->>Mink: setRequestHeader("X-Config-No-Override", names) [if driver supports]
Context->>Context: $_SERVER['HTTP_X_CONFIG_NO_OVERRIDE']=names
Context->>Context: putenv('HTTP_X_CONFIG_NO_OVERRIDE=names')
Context->>Context: set $restHeaders['X-Config-No-Override']=names (if present)
end
Behat->>Mink: perform HTTP step (visit/login)
Mink->>SUT: HTTP request (may include X-Config-No-Override)
SUT->>SUT: read header/$_SERVER -> choose getOriginal() vs get()
SUT->>Mink: response
Mink->>Behat: result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.1.46)Composer install failed: this project depends on private packages that require authentication (e.g. GitLab/GitHub, Laravel Nova, etc.). Instead, run PHPStan in a CI/CD pipeline where you can use custom packages — our pipeline remediation tool can use the PHPStan output from your CI/CD pipeline. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Drupal/ConfigOverrideTrait.php`:
- Around line 115-117: The early return in ConfigOverrideTrait when
$this->configOverrideSkipBeforeStep or $this->configOverrideDisabledNames === []
exits without clearing the propagated "no-override" signal, allowing
X-Config-No-Override to persist via $_SERVER, env, $restHeaders or request
headers; before returning, explicitly reset/clear the override signal state
(e.g. unset any $_SERVER['HTTP_X_CONFIG_NO_OVERRIDE'], clear related env vars
and remove the header from optional $restHeaders or the request header
container) so previous values do not bleed into later scenarios.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 078aa6e5-f710-4366-8008-90cc18a592ad
📒 Files selected for processing (9)
README.mdSTEPS.mdsrc/Drupal/ConfigOverrideTrait.phptests/behat/bootstrap/FeatureContext.phptests/behat/features/drupal_config_override.featuretests/behat/fixtures_drupal/d10/web/modules/custom/mysite_core/mysite_core.routing.ymltests/behat/fixtures_drupal/d10/web/modules/custom/mysite_core/src/Controller/TestContent.phptests/behat/fixtures_drupal/d11/web/modules/custom/mysite_core/mysite_core.routing.ymltests/behat/fixtures_drupal/d11/web/modules/custom/mysite_core/src/Controller/TestContent.php
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #626 +/- ##
==========================================
+ Coverage 97.47% 97.50% +0.02%
==========================================
Files 42 43 +1
Lines 2928 2960 +32
==========================================
+ Hits 2854 2886 +32
Misses 74 74 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/behat/features/drupal_config_override.feature`:
- Line 1: Add a descriptive feature-level tag (e.g., `@config-override`) to the
"Check that ConfigOverrideTrait works" feature so it can be selected
independently; update the feature header in the
tests/behat/features/drupal_config_override.feature by inserting the tag line
(for example "@config-override") immediately above or on the same line as the
"Feature: Check that ConfigOverrideTrait works" declaration so all scenarios in
that feature inherit the tag.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: abd712ca-b21c-4b76-a3b6-099bbfbfd5ac
📒 Files selected for processing (6)
scripts/provision.shtests/behat/features/drupal_config_override.featuretests/behat/fixtures_drupal/d10/web/modules/custom/mysite_core/mysite_core.routing.ymltests/behat/fixtures_drupal/d10/web/modules/custom/mysite_core/src/Controller/TestContent.phptests/behat/fixtures_drupal/d11/web/modules/custom/mysite_core/mysite_core.routing.ymltests/behat/fixtures_drupal/d11/web/modules/custom/mysite_core/src/Controller/TestContent.php
Closes #571
Summary
Adds a new
ConfigOverrideTraitundersrc/Drupal/ConfigOverrideTrait.phpthat lets a Behat scenario tell the Drupal system under test (SUT) to ignore config overrides defined insettings.phpfor specific config objects. Because Behat runs in a separate process from the SUT, the trait signals intent via a request header, a$_SERVERentry, and an environment variable; the SUT is responsible for reading the signal and callingImmutableConfig::getOriginal()instead ofImmutableConfig::get().Activation is driven by tags on a feature or scenario:
@disable-config-override:CONFIG_NAME- add one per config object; multiple tags are combined into a comma-separated list.@behat-steps-skip:configOverrideBeforeScenario- opt out of the trait entirely for a scenario.@behat-steps-skip:configOverrideBeforeStep- keep tag parsing but skip header propagation.The
BeforeStephook re-applies the header on every step because some steps (for example, Drupal Extension login) reset headers set earlier in the scenario. Selenium-based drivers are skipped silently because they cannot set request headers. When the consuming context also usesRestTrait, the$restHeadersarray is populated via a softproperty_exists()check so standalone REST requests receive the same signal.Changes
src/Drupal/ConfigOverrideTrait.php- new trait withconfigOverrideBeforeScenarioandconfigOverrideBeforeStephooks, tag parsing, BrowserKit header propagation,$_SERVER+putenv()fallbacks, and a softRestTraitbridge.tests/behat/features/drupal_config_override.feature- 6 scenarios covering: no tag, single tag, multiple tags (comma-joined), header surviving a login step,behat-steps-skip:configOverrideBeforeScenario, andbehat-steps-skip:configOverrideBeforeStep. Reaches 100% line coverage for the new trait.tests/behat/bootstrap/FeatureContext.php- registers the new trait on the default context.tests/behat/fixtures_drupal/d10/.../mysite_core.routing.ymlandsrc/Controller/TestContent.php- add/mysite_core/test-config-no-override-headerroute and controller that echoes the receivedX-Config-No-Overrideheader so scenarios can assert it reached the SUT.tests/behat/fixtures_drupal/d11/...- mirror of the D10 route + controller.STEPS.mdandREADME.md- regenerated viaahoy update-docs.Before / After
Test plan
ahoy lint(phpcs, phpstan, rector --dry-run, gherkinlint) passes locally.ahoy test-unit(189 tests, 312 assertions) passes locally.ahoy test-bdd tests/behat/features/drupal_config_override.featurepasses locally (6 scenarios, 100% line coverage forConfigOverrideTrait).Overview
This PR adds a Drupal-specific Behat trait that lets scenarios signal the system-under-test (SUT) to ignore config overrides from settings.php for specified config objects. Activation is tag-driven and requires no new step definitions.
Key Changes
Core Implementation
Tests & Fixtures
Documentation
Step Definition Compliance (CONTRIBUTING.md)
Testing & CI
Notes for Reviewers