Tenant not determined during browser testing#629
Closed
moisish wants to merge 2 commits intospatie:mainfrom
Closed
Tenant not determined during browser testing#629moisish wants to merge 2 commits intospatie:mainfrom
moisish wants to merge 2 commits intospatie:mainfrom
Conversation
Collaborator
|
Hi @moisish, I think the PR introduces an unnecessary complexity. Your workaround requires less code lines than your PR: and I think this is enough. Thanks for your effort. |
Contributor
Author
|
This is an issue that other people will have. The default behaviour does not change so I disagree with the unnecessary complexity. |
Collaborator
|
Your workaround could be documented in our doc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Problem
When running Pest browser tests, the current tenant is never determined. This is because
Multitenancy::configureRequests()checks$this->app->runningInConsole()and skipsdetermineCurrentTenant()entirely when running in a console context.Since the test runner executes in the console, tenant resolution is bypassed — even though the application is handling
real HTTP requests during browser tests.
My Workaround
To work around this in my project, I had to register a custom middleware in my
TestCase::setUp()that manuallyresolves the tenant for every request:
This works but is boilerplate that every user running browser tests would need to add.
Proposed Fix
Add a new config option determine_current_tenant_in_tests (default false) that allows tenant determination when running in a test context.
It only applies during tests and is fully opt-in — no change in default behavior.
src/Multitenancy.php — Updated configureRequests():