Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Improve RootUrl and UrlGenerator bootstrappers #1294

Merged
merged 16 commits into from
Jan 16, 2025

Conversation

stancl
Copy link
Member

@stancl stancl commented Jan 16, 2025

PR description copied from https://github.com/tenancy-for-laravel/v4/pull/60

RootUrlBootstrapper

The bootstrapper now only has an effect in CLI by default. To make the bootstrapper have an effect in the tests (e.g. for testing if it works correctly), RootUrlBootstrapper::$rootUrlOverrideInTests has to be set to true.

Apart from the fact that the bootstrapper should only have an effect in CLI, I added this because I noticed that Livewire::test() is broken when using this bootstrapper with path identification – during Livewire::test(), LW creates a route (livewire-unit-test-endpoint) that can't be accessed when using the root URL override with path identification. It can't be accessed because when the root URL is overridden like "app.test/tenantfoo", the app tries to reach "tenantfoo/livewire-unit-test-endpoint", which is a route that doesn't exist, and I haven't found any way of dealing with that.

RootUrlBootstrapper (UrlGenerator override)

Resolving app('url') was always creating new instances of TenancyUrlGenerator because the instance creation was handled in the closure passed to app()->extend(). This is now solved by creating the instance before binding it to 'url'.

TenancyUrlGenerator also wasn't properly reverted to the original UrlGenerator while ending tenancy – solved this by using app()->extend() in the bootstrapper's revert() instead of app()->bind().

Combining RootUrlBootstrapper with UrlGeneratorBootstrapper (section updated)

RootUrlBootstrapper cannot be combined with UrlGeneratorBootstrapper because allowing that introduces too much unnecessary complexity, and there aren't really use cases for combining these bootstrappers. So we should recommend only using one, or the other, based on the identification method (RootUrlBootstrapper -- multi-domain, UrlGeneratorBootstrapper -- path).

@stancl stancl marked this pull request as ready for review January 16, 2025 09:26
@stancl stancl merged commit 5d3b3d3 into master Jan 16, 2025
4 checks passed
@stancl stancl deleted the fix-url-bootstrappers branch January 16, 2025 09:30
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

Attention: Patch coverage is 76.92308% with 6 lines in your changes missing coverage. Please review.

Project coverage is 84.66%. Comparing base (7944472) to head (470b84d).
Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
src/Bootstrappers/RootUrlBootstrapper.php 72.72% 3 Missing ⚠️
src/Bootstrappers/UrlGeneratorBootstrapper.php 84.61% 2 Missing ⚠️
src/Concerns/ParallelCommand.php 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1294      +/-   ##
============================================
- Coverage     85.00%   84.66%   -0.34%     
- Complexity     1027     1053      +26     
============================================
  Files           174      176       +2     
  Lines          3020     3084      +64     
============================================
+ Hits           2567     2611      +44     
- Misses          453      473      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants