mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 22:34:03 +00:00
Clean up global state (static properties) in before/afterEach
This commit is contained in:
parent
52d10d36f9
commit
53b2181779
5 changed files with 30 additions and 5 deletions
|
|
@ -37,12 +37,16 @@ use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
|||
use Stancl\Tenancy\Bootstrappers\BroadcastTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper;
|
||||
use Stancl\Tenancy\CacheManager;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->mockConsoleOutput = false;
|
||||
|
||||
config(['cache.default' => $cacheDriver = 'redis']);
|
||||
PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver];
|
||||
// Reset static properties of classes used in this test file to their default values
|
||||
BroadcastTenancyBootstrapper::$credentialsMap = [];
|
||||
TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably'];
|
||||
UrlTenancyBootstrapper::$rootUrlOverride = null;
|
||||
|
||||
Event::listen(
|
||||
TenantCreated::class,
|
||||
|
|
@ -56,7 +60,11 @@ beforeEach(function () {
|
|||
});
|
||||
|
||||
afterEach(function () {
|
||||
// Reset static properties of classes used in this test file to their default values
|
||||
UrlTenancyBootstrapper::$rootUrlOverride = null;
|
||||
PrefixCacheTenancyBootstrapper::$tenantCacheStores = [];
|
||||
TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably'];
|
||||
BroadcastTenancyBootstrapper::$credentialsMap = [];
|
||||
});
|
||||
|
||||
test('database data is separated', function () {
|
||||
|
|
|
|||
|
|
@ -13,12 +13,17 @@ use Stancl\Tenancy\Tests\Etc\TestingBroadcaster;
|
|||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||
use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
withTenantDatabases();
|
||||
TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably'];
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably'];
|
||||
});
|
||||
|
||||
test('bound broadcaster instance is the same before initializing tenancy and after ending it', function() {
|
||||
config(['broadcasting.default' => 'null']);
|
||||
TenancyBroadcastManager::$tenantBroadcasters[] = 'null';
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
|
|||
use Stancl\Tenancy\Resolvers\DomainTenantResolver;
|
||||
|
||||
beforeEach(function () {
|
||||
InitializeTenancyByDomain::$onFail = null;
|
||||
|
||||
Route::group([
|
||||
'middleware' => InitializeTenancyByDomain::class,
|
||||
], function () {
|
||||
|
|
@ -23,6 +25,10 @@ beforeEach(function () {
|
|||
config(['tenancy.models.tenant' => DomainTenant::class]);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
InitializeTenancyByDomain::$onFail = null;
|
||||
});
|
||||
|
||||
test('tenant can be identified using hostname', function () {
|
||||
$tenant = DomainTenant::create();
|
||||
|
||||
|
|
@ -89,9 +95,6 @@ test('onfail logic can be customized', function () {
|
|||
});
|
||||
|
||||
test('throw correct exception when onFail is null and universal routes are enabled', function () {
|
||||
// un-define onFail logic
|
||||
InitializeTenancyByDomain::$onFail = null;
|
||||
|
||||
// Enable UniversalRoute feature
|
||||
Route::middlewareGroup('universal', []);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ beforeEach(function () {
|
|||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
PrefixCacheTenancyBootstrapper::$tenantCacheStores = [];
|
||||
});
|
||||
|
||||
test('global cache manager stores data in global cache', function (string $bootstrapper) {
|
||||
config(['tenancy.bootstrappers' => [$bootstrapper]]);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,16 @@ use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper;
|
|||
|
||||
beforeEach(function() {
|
||||
config(['mail.default' => 'smtp']);
|
||||
MailTenancyBootstrapper::$credentialsMap = [];
|
||||
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
MailTenancyBootstrapper::$credentialsMap = [];
|
||||
});
|
||||
|
||||
// Initialize tenancy as $tenant and assert that the smtp mailer's transport has the correct password
|
||||
function assertMailerTransportUsesPassword(string|null $password) {
|
||||
$manager = app(MailManager::class);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue