From ab02d2885c48d86f403dc5e4093b4fe087ac28a8 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 29 Aug 2024 15:58:50 +0200 Subject: [PATCH] Make RootUrlBootstrapper run ONLY in CLI by default (add $rootUrlOverrideInTests), work with resolved UrlGenerator --- src/Bootstrappers/RootUrlBootstrapper.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Bootstrappers/RootUrlBootstrapper.php b/src/Bootstrappers/RootUrlBootstrapper.php index 6a523673..bd49feda 100644 --- a/src/Bootstrappers/RootUrlBootstrapper.php +++ b/src/Bootstrappers/RootUrlBootstrapper.php @@ -36,20 +36,24 @@ class RootUrlBootstrapper implements TenancyBootstrapper protected string|null $originalRootUrl = null; + public static bool $rootUrlOverrideInTests = false; + public function __construct( - protected UrlGenerator $urlGenerator, protected Repository $config, protected Application $app, ) {} public function bootstrap(Tenant $tenant): void { - if ($this->app->runningInConsole() && static::$rootUrlOverride) { - $this->originalRootUrl = $this->urlGenerator->to('/'); + $shouldRunInTests = ! app()->runningUnitTests() || static::$rootUrlOverrideInTests; + $shouldRun = $this->app->runningInConsole() && $shouldRunInTests && static::$rootUrlOverride; + + if ($shouldRun) { + $this->originalRootUrl = $this->app['url']->to('/'); $newRootUrl = (static::$rootUrlOverride)($tenant, $this->originalRootUrl); - $this->urlGenerator->forceRootUrl($newRootUrl); + $this->app['url']->forceRootUrl($newRootUrl); $this->config->set('app.url', $newRootUrl); } } @@ -57,7 +61,7 @@ class RootUrlBootstrapper implements TenancyBootstrapper public function revert(): void { if ($this->originalRootUrl) { - $this->urlGenerator->forceRootUrl($this->originalRootUrl); + $this->app['url']->forceRootUrl($this->originalRootUrl); $this->config->set('app.url', $this->originalRootUrl); } }