diff --git a/assets/config.php b/assets/config.php index 3c55fda8..8d6c4570 100644 --- a/assets/config.php +++ b/assets/config.php @@ -4,6 +4,7 @@ declare(strict_types=1); use Stancl\Tenancy\Middleware; use Stancl\Tenancy\Resolvers; +use Stancl\Tenancy\Bootstrappers; use Stancl\Tenancy\Enums\RouteMode; use Stancl\Tenancy\UniqueIdentifierGenerators; @@ -129,27 +130,27 @@ return [ */ 'bootstrappers' => [ // Basic Laravel features - Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper::class, - Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper::class, - // Stancl\Tenancy\Bootstrappers\CacheTagsBootstrapper::class, // Alternative to PrefixCacheTenancyBootstrapper - Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class, - Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class, - // Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed + Bootstrappers\DatabaseTenancyBootstrapper::class, + Bootstrappers\CacheTenancyBootstrapper::class, + // Bootstrappers\CacheTagsBootstrapper::class, // Alternative to PrefixCacheTenancyBootstrapper + Bootstrappers\FilesystemTenancyBootstrapper::class, + Bootstrappers\QueueTenancyBootstrapper::class, + // Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed // Support for edge cases - Stancl\Tenancy\Bootstrappers\SessionTenancyBootstrapper::class, - Stancl\Tenancy\Bootstrappers\BatchTenancyBootstrapper::class, + Bootstrappers\DatabaseSessionBootstrapper::class, + Bootstrappers\JobBatchBootstrapper::class, // Configurable bootstrappers - // Stancl\Tenancy\Bootstrappers\RootUrlBootstrapper::class, - // Stancl\Tenancy\Bootstrappers\UrlGeneratorBootstrapper::class, - // Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper::class, // Note: Queueing mail requires using QueueTenancyBootstrapper with $forceRefresh set to true - // Stancl\Tenancy\Bootstrappers\BroadcastingConfigBootstrapper::class, - // Stancl\Tenancy\Bootstrappers\BroadcastingChannelPrefixBootstrapper::class, + // Bootstrappers\RootUrlBootstrapper::class, + // Bootstrappers\UrlGeneratorBootstrapper::class, + // Bootstrappers\MailTenancyBootstrapper::class, // Note: Queueing mail requires using QueueTenancyBootstrapper with $forceRefresh set to true + // Bootstrappers\BroadcastingConfigBootstrapper::class, + // Bootstrappers\BroadcastingChannelPrefixBootstrapper::class, // Integration bootstrappers - // Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteTenancyBootstrapper::class, - // Stancl\Tenancy\Bootstrappers\Integrations\ScoutTenancyBootstrapper::class, + // Bootstrappers\Integrations\FortifyRouteTenancyBootstrapper::class, + // Bootstrappers\Integrations\ScoutTenancyBootstrapper::class, ], /** @@ -295,7 +296,7 @@ return [ 'redis' => [ 'prefix_base' => 'tenant', // Each key in Redis will be prepended by this prefix_base, followed by the tenant id. 'prefixed_connections' => [ // Redis connections whose keys are prefixed, to separate one tenant's keys from another. - // 'default', + 'default', ], ], diff --git a/src/Bootstrappers/CacheTagsBootstrapper.php b/src/Bootstrappers/CacheTagsBootstrapper.php index aabbc8f8..2c59ab1e 100644 --- a/src/Bootstrappers/CacheTagsBootstrapper.php +++ b/src/Bootstrappers/CacheTagsBootstrapper.php @@ -10,14 +10,11 @@ use Illuminate\Support\Facades\Cache; use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\Tenant; -// todo@rename some bootstrappers end in TenancyBootstrapper and others don't - make this consistent or make the difference clear - /** - * todo@name rename? - * * Separate tenant cache using tagging. + * * This is the legacy approach. Some things, like dependency injection, won't work properly with this bootstrapper. - * PrefixCacheTenancyBootstrapper is the recommended bootstrapper for cache separation. + * CacheTenancyBootstrapper is the recommended bootstrapper for cache separation. */ class CacheTagsBootstrapper implements TenancyBootstrapper { diff --git a/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php b/src/Bootstrappers/CacheTenancyBootstrapper.php similarity index 95% rename from src/Bootstrappers/PrefixCacheTenancyBootstrapper.php rename to src/Bootstrappers/CacheTenancyBootstrapper.php index ad0ea6f4..a1336bc1 100644 --- a/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php +++ b/src/Bootstrappers/CacheTenancyBootstrapper.php @@ -12,7 +12,10 @@ use Illuminate\Support\Facades\Cache; use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\Tenant; -class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper +/** + * Makes cache tenant-aware by applying a prefix. + */ +class CacheTenancyBootstrapper implements TenancyBootstrapper { protected string|null $originalPrefix = null; public static array $tenantCacheStores = []; // E.g. ['redis'] diff --git a/src/Bootstrappers/SessionTenancyBootstrapper.php b/src/Bootstrappers/DatabaseSessionBootstrapper.php similarity index 95% rename from src/Bootstrappers/SessionTenancyBootstrapper.php rename to src/Bootstrappers/DatabaseSessionBootstrapper.php index 80c657a0..467eaa2f 100644 --- a/src/Bootstrappers/SessionTenancyBootstrapper.php +++ b/src/Bootstrappers/DatabaseSessionBootstrapper.php @@ -11,15 +11,13 @@ use Illuminate\Session\SessionManager; use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\Tenant; -// todo@rename this should be DB-specific - /** * This resets the database connection used by the database session driver. * * It runs each time tenancy is initialized or ended. * That way the session driver always uses the current DB connection. */ -class SessionTenancyBootstrapper implements TenancyBootstrapper +class DatabaseSessionBootstrapper implements TenancyBootstrapper { public function __construct( protected Repository $config, diff --git a/src/Bootstrappers/Integrations/FortifyRouteTenancyBootstrapper.php b/src/Bootstrappers/Integrations/FortifyRouteBootstrapper.php similarity index 98% rename from src/Bootstrappers/Integrations/FortifyRouteTenancyBootstrapper.php rename to src/Bootstrappers/Integrations/FortifyRouteBootstrapper.php index d2e5b6ef..e2290c67 100644 --- a/src/Bootstrappers/Integrations/FortifyRouteTenancyBootstrapper.php +++ b/src/Bootstrappers/Integrations/FortifyRouteBootstrapper.php @@ -16,7 +16,7 @@ use Stancl\Tenancy\Resolvers\PathTenantResolver; * * Works with path and query string identification. */ -class FortifyRouteTenancyBootstrapper implements TenancyBootstrapper +class FortifyRouteBootstrapper implements TenancyBootstrapper { /** * Make Fortify actions redirect to custom routes. diff --git a/src/Bootstrappers/Integrations/ScoutTenancyBootstrapper.php b/src/Bootstrappers/Integrations/ScoutPrefixBootstrapper.php similarity index 88% rename from src/Bootstrappers/Integrations/ScoutTenancyBootstrapper.php rename to src/Bootstrappers/Integrations/ScoutPrefixBootstrapper.php index da5a921a..bb5e9b6d 100644 --- a/src/Bootstrappers/Integrations/ScoutTenancyBootstrapper.php +++ b/src/Bootstrappers/Integrations/ScoutPrefixBootstrapper.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Config\Repository; use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\Tenant; -class ScoutTenancyBootstrapper implements TenancyBootstrapper +class ScoutPrefixBootstrapper implements TenancyBootstrapper { protected ?string $originalScoutPrefix = null; @@ -19,7 +19,7 @@ class ScoutTenancyBootstrapper implements TenancyBootstrapper public function bootstrap(Tenant $tenant): void { - if ($this->originalScoutPrefix !== null) { + if ($this->originalScoutPrefix === null) { $this->originalScoutPrefix = $this->config->get('scout.prefix'); } diff --git a/src/Bootstrappers/BatchTenancyBootstrapper.php b/src/Bootstrappers/JobBatchBootstrapper.php similarity index 90% rename from src/Bootstrappers/BatchTenancyBootstrapper.php rename to src/Bootstrappers/JobBatchBootstrapper.php index 52a50ef6..845575a0 100644 --- a/src/Bootstrappers/BatchTenancyBootstrapper.php +++ b/src/Bootstrappers/JobBatchBootstrapper.php @@ -10,8 +10,10 @@ use Illuminate\Database\DatabaseManager; use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\Tenant; -// todo add docblock -class BatchTenancyBootstrapper implements TenancyBootstrapper +/** + * Adds support for running queued tenant jobs in batches. + */ +class JobBatchBootstrapper implements TenancyBootstrapper { /** * The previous database connection instance. diff --git a/src/Bootstrappers/MailTenancyBootstrapper.php b/src/Bootstrappers/MailConfigBootstrapper.php similarity index 97% rename from src/Bootstrappers/MailTenancyBootstrapper.php rename to src/Bootstrappers/MailConfigBootstrapper.php index 9880d2c4..60028cc1 100644 --- a/src/Bootstrappers/MailTenancyBootstrapper.php +++ b/src/Bootstrappers/MailConfigBootstrapper.php @@ -9,7 +9,7 @@ use Illuminate\Foundation\Application; use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\Tenant; -class MailTenancyBootstrapper implements TenancyBootstrapper +class MailConfigBootstrapper implements TenancyBootstrapper { /** * Tenant properties to be mapped to config (similarly to the TenantConfig feature). diff --git a/src/Tenancy.php b/src/Tenancy.php index dea62068..d1661130 100644 --- a/src/Tenancy.php +++ b/src/Tenancy.php @@ -44,7 +44,6 @@ class Tenancy return; } - // TODO: Remove this (so that runForMultiple() is still performant) and make the FS bootstrapper work either way if ($this->initialized) { $this->end(); } diff --git a/tests/BatchTest.php b/tests/BatchTest.php index 24cb7c59..91ed3c0e 100644 --- a/tests/BatchTest.php +++ b/tests/BatchTest.php @@ -2,7 +2,7 @@ use Illuminate\Bus\BatchRepository; use Illuminate\Support\Facades\Event; -use Stancl\Tenancy\Bootstrappers\BatchTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\JobBatchBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Events\TenancyInitialized; @@ -14,7 +14,7 @@ beforeEach(function () { config([ 'tenancy.bootstrappers' => [ DatabaseTenancyBootstrapper::class, - BatchTenancyBootstrapper::class, + JobBatchBootstrapper::class, ], ]); diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 77e14349..89ef438b 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -38,7 +38,7 @@ use Stancl\Tenancy\Overrides\TenancyBroadcastManager; use Stancl\Tenancy\Middleware\InitializeTenancyByPath; use Stancl\Tenancy\Bootstrappers\CacheTagsBootstrapper; use Illuminate\Routing\Exceptions\UrlGenerationException; -use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\MailConfigBootstrapper; use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\UrlGeneratorBootstrapper; use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; @@ -46,15 +46,15 @@ use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\BroadcastingConfigBootstrapper; -use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\BroadcastChannelPrefixBootstrapper; -use Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteBootstrapper; beforeEach(function () { $this->mockConsoleOutput = false; config(['cache.default' => $cacheDriver = 'redis']); - PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; + CacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; // Reset static properties of classes used in this test file to their default values BroadcastingConfigBootstrapper::$credentialsMap = []; TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably']; @@ -74,7 +74,7 @@ beforeEach(function () { afterEach(function () { // Reset static properties of classes used in this test file to their default values RootUrlBootstrapper::$rootUrlOverride = null; - PrefixCacheTenancyBootstrapper::$tenantCacheStores = []; + CacheTenancyBootstrapper::$tenantCacheStores = []; TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably']; BroadcastingConfigBootstrapper::$credentialsMap = []; TenancyUrlGenerator::$prefixRouteNames = false; @@ -148,7 +148,7 @@ test('cache data is separated', function (string $bootstrapper) { expect(Cache::get('foo'))->toBe('central'); })->with([ CacheTagsBootstrapper::class, - PrefixCacheTenancyBootstrapper::class, + CacheTenancyBootstrapper::class, ]); test('redis data is separated', function () { @@ -453,7 +453,7 @@ test('BroadcastingConfigBootstrapper makes the app use broadcasters with the cor }); test('MailTenancyBootstrapper maps tenant mail credentials to config as specified in the $credentialsMap property and makes the mailer use tenant credentials', function() { - MailTenancyBootstrapper::$credentialsMap = [ + MailConfigBootstrapper::$credentialsMap = [ 'mail.mailers.smtp.username' => 'smtp_username', 'mail.mailers.smtp.password' => 'smtp_password' ]; @@ -462,7 +462,7 @@ test('MailTenancyBootstrapper maps tenant mail credentials to config as specifie 'mail.default' => 'smtp', 'mail.mailers.smtp.username' => $defaultUsername = 'default username', 'mail.mailers.smtp.password' => 'no password', - 'tenancy.bootstrappers' => [MailTenancyBootstrapper::class], + 'tenancy.bootstrappers' => [MailConfigBootstrapper::class], ]); $tenant = Tenant::create(['smtp_password' => $password = 'testing password']); @@ -479,11 +479,11 @@ test('MailTenancyBootstrapper maps tenant mail credentials to config as specifie }); test('MailTenancyBootstrapper reverts the config and mailer credentials to default when tenancy ends', function() { - MailTenancyBootstrapper::$credentialsMap = ['mail.mailers.smtp.password' => 'smtp_password']; + MailConfigBootstrapper::$credentialsMap = ['mail.mailers.smtp.password' => 'smtp_password']; config([ 'mail.default' => 'smtp', 'mail.mailers.smtp.password' => $defaultPassword = 'no password', - 'tenancy.bootstrappers' => [MailTenancyBootstrapper::class], + 'tenancy.bootstrappers' => [MailConfigBootstrapper::class], ]); tenancy()->initialize(Tenant::create(['smtp_password' => $tenantPassword = 'testing password'])); @@ -676,7 +676,7 @@ test('url generator bootstrapper can make route helper generate links with the t }); test('fortify route tenancy bootstrapper updates fortify config correctly', function() { - config(['tenancy.bootstrappers' => [FortifyRouteTenancyBootstrapper::class]]); + config(['tenancy.bootstrappers' => [FortifyRouteBootstrapper::class]]); $originalFortifyHome = config('fortify.home'); $originalFortifyRedirects = config('fortify.redirects'); @@ -697,10 +697,10 @@ test('fortify route tenancy bootstrapper updates fortify config correctly', func return true; })->name($pathIdWelcomeRouteName = 'path.welcome'); - FortifyRouteTenancyBootstrapper::$fortifyHome = $homeRouteName; + FortifyRouteBootstrapper::$fortifyHome = $homeRouteName; // Make login redirect to the central welcome route - FortifyRouteTenancyBootstrapper::$fortifyRedirectMap['login'] = [ + FortifyRouteBootstrapper::$fortifyRedirectMap['login'] = [ 'route_name' => $welcomeRouteName, 'context' => Context::CENTRAL, ]; @@ -717,7 +717,7 @@ test('fortify route tenancy bootstrapper updates fortify config correctly', func expect(config('fortify.redirects'))->toBe($originalFortifyRedirects); // Making a route's context will pass the tenant parameter to the route - FortifyRouteTenancyBootstrapper::$fortifyRedirectMap['login']['context'] = Context::TENANT; + FortifyRouteBootstrapper::$fortifyRedirectMap['login']['context'] = Context::TENANT; tenancy()->initialize($tenant); @@ -725,8 +725,8 @@ test('fortify route tenancy bootstrapper updates fortify config correctly', func // Make the home and login route accept the tenant as a route parameter // To confirm that tenant route parameter gets filled automatically too (path identification works as well as query string) - FortifyRouteTenancyBootstrapper::$fortifyHome = $pathIdHomeRouteName; - FortifyRouteTenancyBootstrapper::$fortifyRedirectMap['login']['route_name'] = $pathIdWelcomeRouteName; + FortifyRouteBootstrapper::$fortifyHome = $pathIdHomeRouteName; + FortifyRouteBootstrapper::$fortifyRedirectMap['login']['route_name'] = $pathIdWelcomeRouteName; tenancy()->end(); diff --git a/tests/SessionBootstrapperTest.php b/tests/DatabaseSessionBootstrapperTest.php similarity index 94% rename from tests/SessionBootstrapperTest.php rename to tests/DatabaseSessionBootstrapperTest.php index 772cb427..20cd19b6 100644 --- a/tests/SessionBootstrapperTest.php +++ b/tests/DatabaseSessionBootstrapperTest.php @@ -6,7 +6,7 @@ use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Route; use Stancl\JobPipeline\JobPipeline; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; -use Stancl\Tenancy\Bootstrappers\SessionTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\DatabaseSessionBootstrapper; use Stancl\Tenancy\Events; use Stancl\Tenancy\Events\TenantCreated; use Stancl\Tenancy\Jobs\CreateDatabase; @@ -48,7 +48,7 @@ test('central helper can be used in tenant requests', function (bool $enabled, b if ($enabled) { config()->set( 'tenancy.bootstrappers', - array_merge(config('tenancy.bootstrappers'), [SessionTenancyBootstrapper::class]), + array_merge(config('tenancy.bootstrappers'), [DatabaseSessionBootstrapper::class]), ); } @@ -101,7 +101,7 @@ test('tenant run helper can be used on central requests', function (bool $enable if ($enabled) { config()->set( 'tenancy.bootstrappers', - array_merge(config('tenancy.bootstrappers'), [SessionTenancyBootstrapper::class]), + array_merge(config('tenancy.bootstrappers'), [DatabaseSessionBootstrapper::class]), ); } diff --git a/tests/GlobalCacheTest.php b/tests/GlobalCacheTest.php index 204ae12a..eefe6a1b 100644 --- a/tests/GlobalCacheTest.php +++ b/tests/GlobalCacheTest.php @@ -11,18 +11,18 @@ use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Bootstrappers\CacheTagsBootstrapper; -use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper; beforeEach(function () { config(['cache.default' => $cacheDriver = 'redis']); - PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; + CacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class); }); afterEach(function () { - PrefixCacheTenancyBootstrapper::$tenantCacheStores = []; + CacheTenancyBootstrapper::$tenantCacheStores = []; }); test('global cache manager stores data in global cache', function (string $bootstrapper) { @@ -57,7 +57,7 @@ test('global cache manager stores data in global cache', function (string $boots expect(cache('def'))->toBe('ghi'); })->with([ CacheTagsBootstrapper::class, - PrefixCacheTenancyBootstrapper::class, + CacheTenancyBootstrapper::class, ]); test('the global_cache helper supports the same syntax as the cache helper', function (string $bootstrapper) { @@ -77,5 +77,5 @@ test('the global_cache helper supports the same syntax as the cache helper', fun expect(cache('foo'))->toBe(null); // tenant cache is not affected })->with([ CacheTagsBootstrapper::class, - PrefixCacheTenancyBootstrapper::class, + CacheTenancyBootstrapper::class, ]); diff --git a/tests/MailTest.php b/tests/MailTest.php index 03f8aa63..6d9dbae5 100644 --- a/tests/MailTest.php +++ b/tests/MailTest.php @@ -8,19 +8,19 @@ use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; -use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\MailConfigBootstrapper; beforeEach(function() { config(['mail.default' => 'smtp']); - config(['tenancy.bootstrappers' => [MailTenancyBootstrapper::class]]); - MailTenancyBootstrapper::$credentialsMap = []; + config(['tenancy.bootstrappers' => [MailConfigBootstrapper::class]]); + MailConfigBootstrapper::$credentialsMap = []; Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class); }); afterEach(function () { - MailTenancyBootstrapper::$credentialsMap = []; + MailConfigBootstrapper::$credentialsMap = []; }); // Initialize tenancy as $tenant and assert that the smtp mailer's transport has the correct password @@ -36,7 +36,7 @@ test('mailer transport uses the correct credentials', function() { withTenantDatabases(); config(['mail.default' => 'smtp', 'mail.mailers.smtp.password' => $defaultPassword = 'DEFAULT']); - MailTenancyBootstrapper::$credentialsMap = ['mail.mailers.smtp.password' => 'smtp_password']; + MailConfigBootstrapper::$credentialsMap = ['mail.mailers.smtp.password' => 'smtp_password']; tenancy()->initialize($tenant = Tenant::create()); assertMailerTransportUsesPassword($defaultPassword); // $tenant->smtp_password is not set, so the default password should be used @@ -61,7 +61,7 @@ test('mailer transport uses the correct credentials', function() { '--realpath' => true, ])->assertExitCode(0); - MailTenancyBootstrapper::$credentialsMap = ['mail.mailers.smtp.password' => 'mail.smtp_password']; + MailConfigBootstrapper::$credentialsMap = ['mail.mailers.smtp.password' => 'mail.smtp_password']; tenancy()->initialize($tenant = Tenant::create(['mail' => ['smtp_password' => $nestedTenantPassword = 'nested']])); assertMailerTransportUsesPassword($nestedTenantPassword); tenancy()->end(); diff --git a/tests/PrefixCacheBootstrapperTest.php b/tests/PrefixCacheBootstrapperTest.php index 45e7ef52..dd9bb798 100644 --- a/tests/PrefixCacheBootstrapperTest.php +++ b/tests/PrefixCacheBootstrapperTest.php @@ -10,34 +10,34 @@ use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Tests\Etc\SpecificCacheStoreService; -use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper; beforeEach(function () { config([ 'tenancy.bootstrappers' => [ - PrefixCacheTenancyBootstrapper::class + CacheTenancyBootstrapper::class ], 'cache.default' => $cacheDriver = 'redis', 'cache.stores.' . $secondCacheDriver = 'redis2' => config('cache.stores.redis'), ]); - PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver, $secondCacheDriver]; - PrefixCacheTenancyBootstrapper::$prefixGenerator = null; + CacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver, $secondCacheDriver]; + CacheTenancyBootstrapper::$prefixGenerator = null; Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class); }); afterEach(function () { - PrefixCacheTenancyBootstrapper::$tenantCacheStores = []; - PrefixCacheTenancyBootstrapper::$prefixGenerator = null; + CacheTenancyBootstrapper::$tenantCacheStores = []; + CacheTenancyBootstrapper::$prefixGenerator = null; }); test('correct cache prefix is used in all contexts', function () { $originalPrefix = config('cache.prefix'); $prefixBase = config('tenancy.cache.prefix_base'); $getDefaultPrefixForTenant = fn (Tenant $tenant) => $originalPrefix . $prefixBase . $tenant->getTenantKey(); - $bootstrapper = app(PrefixCacheTenancyBootstrapper::class); + $bootstrapper = app(CacheTenancyBootstrapper::class); $expectCachePrefixToBe = function (string $prefix) { expect($prefix) @@ -180,7 +180,7 @@ test('cache is prefixed correctly when using a repository injected in a singleto test('specific central cache store can be used inside a service', function () { // Make sure 'redis' (the default store) is the only prefixed store - PrefixCacheTenancyBootstrapper::$tenantCacheStores = ['redis']; + CacheTenancyBootstrapper::$tenantCacheStores = ['redis']; // Name of the non-default, central cache store that we'll use using cache()->store($cacheStore) $cacheStore = 'redis2'; @@ -217,7 +217,7 @@ test('specific central cache store can be used inside a service', function () { test('only the stores specified in tenantCacheStores get prefixed', function () { // Make sure the currently used store ('redis') is the only store in $tenantCacheStores - PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$prefixedStore = 'redis']; + CacheTenancyBootstrapper::$tenantCacheStores = [$prefixedStore = 'redis']; $centralValue = 'central-value'; $assertStoreIsNotPrefixed = function (string $unprefixedStore) use ($prefixedStore, $centralValue) { @@ -266,7 +266,7 @@ test('non default stores get prefixed too when specified in tenantCacheStores', $tenant = Tenant::create(); $defaultPrefix = cache()->store()->getPrefix(); - $bootstrapper = app(PrefixCacheTenancyBootstrapper::class); + $bootstrapper = app(CacheTenancyBootstrapper::class); // The prefix is the same for both drivers in the central context expect(cache()->store('redis')->getPrefix())->toBe($defaultPrefix); @@ -284,12 +284,12 @@ test('non default stores get prefixed too when specified in tenantCacheStores', test('cache store prefix generation can be customized', function() { // Use custom prefix generator - PrefixCacheTenancyBootstrapper::generatePrefixUsing($customPrefixGenerator = function (Tenant $tenant) { + CacheTenancyBootstrapper::generatePrefixUsing($customPrefixGenerator = function (Tenant $tenant) { return 'redis_tenant_cache_' . $tenant->getTenantKey(); }); - expect(PrefixCacheTenancyBootstrapper::$prefixGenerator)->toBe($customPrefixGenerator); - expect(app(PrefixCacheTenancyBootstrapper::class)->generatePrefix($tenant = Tenant::create())) + expect(CacheTenancyBootstrapper::$prefixGenerator)->toBe($customPrefixGenerator); + expect(app(CacheTenancyBootstrapper::class)->generatePrefix($tenant = Tenant::create())) ->toBe($customPrefixGenerator($tenant)); tenancy()->initialize($tenant = Tenant::create()); @@ -316,7 +316,7 @@ test('stores get prefixed using the default way if no prefix generator is specif // All stores use the default way of generating the prefix when the prefix generator isn't specified expect($defaultPrefix) - ->toBe(app(PrefixCacheTenancyBootstrapper::class)->generatePrefix($tenant)) + ->toBe(app(CacheTenancyBootstrapper::class)->generatePrefix($tenant)) ->toBe(cache()->getPrefix()) // Get prefix of the default store ('redis') ->toBe(cache()->store('redis2')->getPrefix()); diff --git a/tests/TestCase.php b/tests/TestCase.php index 95619a01..3ae67bdd 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -15,13 +15,13 @@ use Stancl\Tenancy\Facades\GlobalCache; use Stancl\Tenancy\TenancyServiceProvider; use Stancl\Tenancy\Facades\Tenancy as TenancyFacade; use Stancl\Tenancy\Bootstrappers\RootUrlBootstrapper; -use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\MailConfigBootstrapper; use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\UrlGeneratorBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\BroadcastingConfigBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; -use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper; abstract class TestCase extends \Orchestra\Testbench\TestCase { @@ -129,10 +129,10 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase ]); $app->singleton(RedisTenancyBootstrapper::class); // todo@samuel use proper approach eg config for singleton registration - $app->singleton(PrefixCacheTenancyBootstrapper::class); // todo@samuel use proper approach eg config for singleton registration + $app->singleton(CacheTenancyBootstrapper::class); // todo@samuel use proper approach eg config for singleton registration $app->singleton(BroadcastingConfigBootstrapper::class); $app->singleton(BroadcastChannelPrefixBootstrapper::class); - $app->singleton(MailTenancyBootstrapper::class); + $app->singleton(MailConfigBootstrapper::class); $app->singleton(RootUrlBootstrapper::class); $app->singleton(UrlGeneratorBootstrapper::class); }