From 6955512a6b36123f2fc308d9f2a27d843858cb15 Mon Sep 17 00:00:00 2001 From: stancl Date: Fri, 22 May 2020 09:01:31 +0000 Subject: [PATCH] Apply fixes from StyleCI --- assets/TenancyServiceProvider.stub.php | 6 +++-- assets/config.php | 2 +- assets/routes.php | 2 +- .../DatabaseTenancyBootstrapper.php | 5 ++-- src/Commands/Migrate.php | 7 +++-- src/Commands/MigrateFresh.php | 1 - src/Commands/Rollback.php | 5 ++-- src/Commands/Seed.php | 3 +-- src/Commands/TenantList.php | 2 +- src/Concerns/TenantAwareCommand.php | 2 +- src/Contracts/Domain.php | 4 ++- src/Contracts/SyncMaster.php | 3 +++ src/Contracts/Syncable.php | 5 ++++ src/Contracts/Tenant.php | 2 ++ .../TenantCouldNotBeIdentifiedException.php | 2 ++ src/Contracts/TenantDatabaseManager.php | 2 +- src/Contracts/TenantResolver.php | 2 ++ src/Contracts/TenantWithDatabase.php | 2 ++ .../Concerns/BelongsToPrimaryModel.php | 2 ++ src/Database/Concerns/BelongsToTenant.php | 2 ++ src/Database/Concerns/CentralConnection.php | 2 ++ src/Database/Concerns/GeneratesIds.php | 2 ++ src/Database/Concerns/HasDataColumn.php | 2 ++ src/Database/Concerns/HasDatabase.php | 2 ++ src/Database/Concerns/HasDomains.php | 2 ++ .../Concerns/HasScopedValidationRules.php | 4 ++- src/Database/Concerns/MaintenanceMode.php | 4 ++- src/Database/Concerns/PrimaryDomain.php | 2 ++ src/Database/Concerns/ResourceSyncing.php | 3 ++- src/Database/Concerns/TenantConnection.php | 2 ++ src/Database/Models/Domain.php | 10 ++++--- src/Database/Models/ImpersonationToken.php | 4 ++- src/Database/Models/Tenant.php | 8 +++--- src/Database/Models/TenantPivot.php | 4 ++- src/Database/ParentModelScope.php | 2 ++ src/Database/TenantCollection.php | 4 ++- src/Database/TenantScope.php | 2 ++ src/DatabaseConfig.php | 2 +- src/DatabaseManager.php | 4 --- src/Events/BootstrappingTenancy.php | 2 ++ src/Events/Contracts/DomainEvent.php | 2 ++ src/Events/Contracts/TenancyEvent.php | 4 ++- src/Events/Contracts/TenantEvent.php | 2 ++ src/Events/CreatingDatabase.php | 5 +++- src/Events/CreatingDomain.php | 2 ++ src/Events/CreatingTenant.php | 2 ++ src/Events/DatabaseCreated.php | 4 ++- src/Events/DatabaseDeleted.php | 2 ++ src/Events/DatabaseMigrated.php | 5 +++- src/Events/DatabaseRolledBack.php | 5 +++- src/Events/DatabaseSeeded.php | 2 ++ src/Events/DeletingDomain.php | 2 ++ src/Events/DeletingTenant.php | 2 ++ src/Events/DomainCreated.php | 2 ++ src/Events/DomainDeleted.php | 2 ++ src/Events/DomainSaved.php | 2 ++ src/Events/DomainUpdated.php | 2 ++ src/Events/EndingTenancy.php | 2 ++ src/Events/InitializingTenancy.php | 2 ++ src/Events/MigratingDatabase.php | 2 ++ src/Events/RevertedToCentralContext.php | 2 ++ src/Events/RevertingToCentralContext.php | 2 ++ src/Events/SavedDomain.php | 5 +++- src/Events/SavedTenant.php | 2 ++ src/Events/SavingDomain.php | 2 ++ src/Events/SavingTenant.php | 2 ++ src/Events/SeedingDatabase.php | 2 ++ ...SyncedResourceChangedInForeignDatabase.php | 2 ++ src/Events/SyncedResourceSaved.php | 2 ++ src/Events/TenancyBootstrapped.php | 2 ++ src/Events/TenancyEnded.php | 4 ++- src/Events/TenancyInitialized.php | 2 ++ src/Events/TenantCreated.php | 2 ++ src/Events/TenantDeleted.php | 2 ++ src/Events/TenantSaved.php | 2 ++ src/Events/TenantUpdated.php | 2 ++ src/Events/UpdatingDomain.php | 2 ++ src/Events/UpdatingTenant.php | 2 ++ .../ModelNotSyncMasterException.php | 4 ++- src/Exceptions/NoConnectionSetException.php | 4 ++- src/Exceptions/NotASubdomainException.php | 4 ++- ...RouteIsMissingTenantParameterException.php | 4 ++- .../TenancyNotInitializedException.php | 6 +++-- src/Features/TelescopeTags.php | 2 +- src/Features/TenantConfig.php | 2 +- src/Features/UserImpersonation.php | 7 ++--- src/Jobs/CreateDatabase.php | 2 +- src/Jobs/DeleteDatabase.php | 1 - src/Listeners/BootstrapTenancy.php | 2 ++ src/Listeners/QueueableListener.php | 2 ++ src/Listeners/RevertToCentralContext.php | 4 ++- src/Listeners/UpdateSyncedResource.php | 6 +++-- .../CheckTenantForMaintenanceMode.php | 5 ++-- src/Middleware/IdentificationMiddleware.php | 4 ++- src/Middleware/InitializeTenancyByPath.php | 4 ++- .../InitializeTenancyBySubdomain.php | 2 +- .../PreventAccessFromCentralDomains.php | 2 ++ src/Middleware/ScopeSessions.php | 4 ++- src/Resolvers/CachedTenantResolver.php | 2 ++ src/Resolvers/DomainTenantResolver.php | 2 ++ src/Resolvers/PathTenantResolver.php | 4 ++- src/Resolvers/RequestDataTenantResolver.php | 2 ++ src/Tenancy.php | 4 ++- ...rmissionControlledMySQLDatabaseManager.php | 2 +- .../PostgreSQLSchemaManager.php | 1 - .../SQLiteDatabaseManager.php | 2 +- src/helpers.php | 4 +-- tests/AutomaticModeTest.php | 11 ++++---- tests/BootstrapperTest.php | 27 ++++++++++--------- tests/CacheManagerTest.php | 9 +++---- tests/CachedTenantResolverTest.php | 4 ++- ...edDomainAndSubdomainIdentificationTest.php | 5 ++-- tests/CommandsTest.php | 27 +++++++++---------- tests/DatabasePreparationTest.php | 7 ++--- tests/DatabaseUsersTest.php | 13 +++++---- tests/DomainTest.php | 5 ++-- tests/Etc/Tenant.php | 2 ++ tests/EventListenerTest.php | 10 +++---- tests/Features/TenantConfigTest.php | 2 +- tests/GlobalCacheTest.php | 9 +++---- tests/MaintenanceModeTest.php | 6 +++-- tests/PathIdentificationTest.php | 10 +++---- tests/QueueTest.php | 11 ++++---- tests/RequestDataIdentificationTest.php | 3 +-- tests/ResourceSyncingTest.php | 21 ++++++++------- tests/ScopeSessionsTest.php | 4 ++- tests/SingleDatabaseTenancyTest.php | 10 +++---- tests/SubdomainTest.php | 5 ++-- tests/TenantAssetTest.php | 11 ++++---- tests/TenantAwareCommandTest.php | 1 - tests/TenantDatabaseManagerTest.php | 14 +++++----- tests/TenantModelTest.php | 25 ++++++++--------- tests/TenantUserImpersonationTest.php | 14 +++++----- 133 files changed, 379 insertions(+), 203 deletions(-) diff --git a/assets/TenancyServiceProvider.stub.php b/assets/TenancyServiceProvider.stub.php index 6fff47a7..ddaf84bb 100644 --- a/assets/TenancyServiceProvider.stub.php +++ b/assets/TenancyServiceProvider.stub.php @@ -1,14 +1,16 @@ Tenant::class, 'internal_prefix' => 'tenancy_', 'id_generator' => Stancl\Tenancy\UUIDGenerator::class, - + 'domain_model' => Domain::class, 'central_domains' => [ '127.0.0.1', diff --git a/assets/routes.php b/assets/routes.php index 54bbb0b2..9223c099 100644 --- a/assets/routes.php +++ b/assets/routes.php @@ -6,4 +6,4 @@ use Illuminate\Support\Facades\Route; Route::get('/tenancy/assets/{path?}', 'Stancl\Tenancy\Controllers\TenantAssetsController@asset') ->where('path', '(.*)') - ->name('stancl.tenancy.asset'); \ No newline at end of file + ->name('stancl.tenancy.asset'); diff --git a/src/Bootstrappers/DatabaseTenancyBootstrapper.php b/src/Bootstrappers/DatabaseTenancyBootstrapper.php index c9d9d791..479b8f34 100644 --- a/src/Bootstrappers/DatabaseTenancyBootstrapper.php +++ b/src/Bootstrappers/DatabaseTenancyBootstrapper.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace Stancl\Tenancy\Bootstrappers; use Stancl\Tenancy\Contracts\TenancyBootstrapper; +use Stancl\Tenancy\Contracts\Tenant; +use Stancl\Tenancy\Contracts\TenantWithDatabase; use Stancl\Tenancy\DatabaseManager; use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException; -use Stancl\Tenancy\Contracts\TenantWithDatabase; -use Stancl\Tenancy\Contracts\Tenant; class DatabaseTenancyBootstrapper implements TenancyBootstrapper { @@ -23,7 +23,6 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper public function bootstrap(Tenant $tenant) { /** @var TenantWithDatabase $tenant */ - $database = $tenant->database()->getName(); if (! $tenant->database()->manager()->databaseExists($database)) { throw new TenantDatabaseDoesNotExistException($database); diff --git a/src/Commands/Migrate.php b/src/Commands/Migrate.php index af289329..69e787fd 100644 --- a/src/Commands/Migrate.php +++ b/src/Commands/Migrate.php @@ -7,11 +7,10 @@ namespace Stancl\Tenancy\Commands; use Illuminate\Console\Command; use Illuminate\Database\Console\Migrations\MigrateCommand; use Illuminate\Database\Migrations\Migrator; -use Stancl\Tenancy\Contracts\TenantWithDatabase; -use Stancl\Tenancy\DatabaseManager; -use Stancl\Tenancy\Events\DatabaseMigrated; use Stancl\Tenancy\Concerns\DealsWithMigrations; use Stancl\Tenancy\Concerns\HasATenantsOption; +use Stancl\Tenancy\DatabaseManager; +use Stancl\Tenancy\Events\DatabaseMigrated; use Stancl\Tenancy\Events\MigratingDatabase; class Migrate extends MigrateCommand @@ -62,7 +61,7 @@ class Migrate extends MigrateCommand $this->line("Tenant: {$tenant['id']}"); event(new MigratingDatabase($tenant)); - + // Migrate parent::handle(); diff --git a/src/Commands/MigrateFresh.php b/src/Commands/MigrateFresh.php index b1c50856..f50e2f5f 100644 --- a/src/Commands/MigrateFresh.php +++ b/src/Commands/MigrateFresh.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Stancl\Tenancy\Commands; use Illuminate\Console\Command; -use Stancl\Tenancy\Contracts\TenantWithDatabase; use Stancl\Tenancy\Concerns\DealsWithMigrations; use Stancl\Tenancy\Concerns\HasATenantsOption; diff --git a/src/Commands/Rollback.php b/src/Commands/Rollback.php index d52f1b04..de8367fc 100644 --- a/src/Commands/Rollback.php +++ b/src/Commands/Rollback.php @@ -7,11 +7,10 @@ namespace Stancl\Tenancy\Commands; use Illuminate\Console\Command; use Illuminate\Database\Console\Migrations\RollbackCommand; use Illuminate\Database\Migrations\Migrator; -use Stancl\Tenancy\Contracts\TenantWithDatabase; -use Stancl\Tenancy\DatabaseManager; -use Stancl\Tenancy\Events\DatabaseRolledBack; use Stancl\Tenancy\Concerns\DealsWithMigrations; use Stancl\Tenancy\Concerns\HasATenantsOption; +use Stancl\Tenancy\DatabaseManager; +use Stancl\Tenancy\Events\DatabaseRolledBack; class Rollback extends RollbackCommand { diff --git a/src/Commands/Seed.php b/src/Commands/Seed.php index f2f704ae..5482a8dd 100644 --- a/src/Commands/Seed.php +++ b/src/Commands/Seed.php @@ -6,10 +6,9 @@ namespace Stancl\Tenancy\Commands; use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Database\Console\Seeds\SeedCommand; -use Stancl\Tenancy\Contracts\TenantWithDatabase; +use Stancl\Tenancy\Concerns\HasATenantsOption; use Stancl\Tenancy\DatabaseManager; use Stancl\Tenancy\Events\DatabaseSeeded; -use Stancl\Tenancy\Concerns\HasATenantsOption; use Stancl\Tenancy\Events\SeedingDatabase; class Seed extends SeedCommand diff --git a/src/Commands/TenantList.php b/src/Commands/TenantList.php index f706a07b..0f3211ab 100644 --- a/src/Commands/TenantList.php +++ b/src/Commands/TenantList.php @@ -39,6 +39,6 @@ class TenantList extends Command ->cursor() ->each(function (Tenant $tenant) { $this->line("[Tenant] id: {$tenant['id']} @ " . implode('; ', $tenant->domains ?? [])); - }); + }); } } diff --git a/src/Concerns/TenantAwareCommand.php b/src/Concerns/TenantAwareCommand.php index 72a394cf..5daa87f6 100644 --- a/src/Concerns/TenantAwareCommand.php +++ b/src/Concerns/TenantAwareCommand.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Stancl\Tenancy\Concerns; +use Stancl\Tenancy\Contracts\Tenant; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Stancl\Tenancy\Contracts\Tenant; trait TenantAwareCommand { diff --git a/src/Contracts/Domain.php b/src/Contracts/Domain.php index ba7d2e2f..b4fa5220 100644 --- a/src/Contracts/Domain.php +++ b/src/Contracts/Domain.php @@ -1,10 +1,12 @@ where(BelongsToTenant::$tenantIdColumn, $this->getTenantKey()); } -} \ No newline at end of file +} diff --git a/src/Database/Concerns/MaintenanceMode.php b/src/Database/Concerns/MaintenanceMode.php index f3f3f339..55e0e46d 100644 --- a/src/Database/Concerns/MaintenanceMode.php +++ b/src/Database/Concerns/MaintenanceMode.php @@ -1,5 +1,7 @@ $data['allowed'] ?? [], ]]); } -} \ No newline at end of file +} diff --git a/src/Database/Concerns/PrimaryDomain.php b/src/Database/Concerns/PrimaryDomain.php index f9b0021f..816e409b 100644 --- a/src/Database/Concerns/PrimaryDomain.php +++ b/src/Database/Concerns/PrimaryDomain.php @@ -1,5 +1,7 @@ triggerSyncEvent(); }); diff --git a/src/Database/Concerns/TenantConnection.php b/src/Database/Concerns/TenantConnection.php index 4d221ecd..a01fa3ef 100644 --- a/src/Database/Concerns/TenantConnection.php +++ b/src/Database/Concerns/TenantConnection.php @@ -1,5 +1,7 @@ domain)->first()) { + $ensureDomainIsNotOccupied = function (self $self) { + if ($domain = self::where('domain', $self->domain)->first()) { if ($domain->getKey() !== $self->getKey()) { throw new DomainOccupiedByOtherTenantException($self->domain); } diff --git a/src/Database/Models/ImpersonationToken.php b/src/Database/Models/ImpersonationToken.php index 2b71067e..4aa63252 100644 --- a/src/Database/Models/ImpersonationToken.php +++ b/src/Database/Models/ImpersonationToken.php @@ -1,5 +1,7 @@ auth_guard = $model->auth_guard ?? config('auth.defaults.guard'); }); } -} \ No newline at end of file +} diff --git a/src/Database/Models/Tenant.php b/src/Database/Models/Tenant.php index b75f028e..070d1d2e 100644 --- a/src/Database/Models/Tenant.php +++ b/src/Database/Models/Tenant.php @@ -1,20 +1,22 @@ tenancy = $tenancy; } -} \ No newline at end of file +} diff --git a/src/Events/Contracts/TenantEvent.php b/src/Events/Contracts/TenantEvent.php index 93470327..951fabfc 100644 --- a/src/Events/Contracts/TenantEvent.php +++ b/src/Events/Contracts/TenantEvent.php @@ -1,5 +1,7 @@ macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string $authGuard = null): ImpersonationToken - { + $tenancy->macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string $authGuard = null): ImpersonationToken { return ImpersonationToken::create([ 'tenant_id' => $tenant->getTenantKey(), 'user_id' => $userId, diff --git a/src/Jobs/CreateDatabase.php b/src/Jobs/CreateDatabase.php index e3252cd2..b02f767e 100644 --- a/src/Jobs/CreateDatabase.php +++ b/src/Jobs/CreateDatabase.php @@ -10,8 +10,8 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Stancl\Tenancy\Contracts\TenantWithDatabase; use Stancl\Tenancy\Contracts\Tenant; +use Stancl\Tenancy\Contracts\TenantWithDatabase; use Stancl\Tenancy\DatabaseManager; use Stancl\Tenancy\Events\CreatingDatabase; use Stancl\Tenancy\Events\DatabaseCreated; diff --git a/src/Jobs/DeleteDatabase.php b/src/Jobs/DeleteDatabase.php index 3fa7b47e..1a8a3add 100644 --- a/src/Jobs/DeleteDatabase.php +++ b/src/Jobs/DeleteDatabase.php @@ -9,7 +9,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Stancl\Tenancy\Contracts\TenantDatabaseManager; use Stancl\Tenancy\Database\Models\Tenant; use Stancl\Tenancy\Events\DatabaseDeleted; diff --git a/src/Listeners/BootstrapTenancy.php b/src/Listeners/BootstrapTenancy.php index baf53791..d03da698 100644 --- a/src/Listeners/BootstrapTenancy.php +++ b/src/Listeners/BootstrapTenancy.php @@ -1,5 +1,7 @@ tenancy)); - } + } } diff --git a/src/Listeners/UpdateSyncedResource.php b/src/Listeners/UpdateSyncedResource.php index c7a5a0cb..40d4d644 100644 --- a/src/Listeners/UpdateSyncedResource.php +++ b/src/Listeners/UpdateSyncedResource.php @@ -1,5 +1,7 @@ tenants->contains($currentTenantMapping); - if (!$mappingExists) { + if (! $mappingExists) { // Here we should call TenantPivot, but we call general Pivot, so that this works // even if people use their own pivot model that is not based on our TenantPivot Pivot::withoutEvents(function () use ($centralModel, $event) { @@ -80,7 +82,7 @@ class UpdateSyncedResource extends QueueableListener return $centralModel->tenants->filter(function ($model) use ($currentTenantMapping) { // Remove the mapping for the current tenant. - return !$currentTenantMapping($model); + return ! $currentTenantMapping($model); }); } diff --git a/src/Middleware/CheckTenantForMaintenanceMode.php b/src/Middleware/CheckTenantForMaintenanceMode.php index 4e0e4828..5554663f 100644 --- a/src/Middleware/CheckTenantForMaintenanceMode.php +++ b/src/Middleware/CheckTenantForMaintenanceMode.php @@ -1,11 +1,12 @@ parameter(static::$tenantParameterName)) { $route->forgetParameter(static::$tenantParameterName); - + if ($tenant = tenancy()->find($id)) { return $tenant; } diff --git a/src/Resolvers/RequestDataTenantResolver.php b/src/Resolvers/RequestDataTenantResolver.php index d9befd5c..2bd5785c 100644 --- a/src/Resolvers/RequestDataTenantResolver.php +++ b/src/Resolvers/RequestDataTenantResolver.php @@ -1,5 +1,7 @@ tenant = $tenant; - + event(new Events\InitializingTenancy($this)); $this->initialized = true; diff --git a/src/TenantDatabaseManagers/PermissionControlledMySQLDatabaseManager.php b/src/TenantDatabaseManagers/PermissionControlledMySQLDatabaseManager.php index de43d502..f8bedc97 100644 --- a/src/TenantDatabaseManagers/PermissionControlledMySQLDatabaseManager.php +++ b/src/TenantDatabaseManagers/PermissionControlledMySQLDatabaseManager.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Stancl\Tenancy\TenantDatabaseManagers; +use Stancl\Tenancy\Concerns\CreatesDatabaseUsers; use Stancl\Tenancy\Contracts\ManagesDatabaseUsers; use Stancl\Tenancy\DatabaseConfig; use Stancl\Tenancy\Exceptions\TenantDatabaseUserAlreadyExistsException; -use Stancl\Tenancy\Concerns\CreatesDatabaseUsers; class PermissionControlledMySQLDatabaseManager extends MySQLDatabaseManager implements ManagesDatabaseUsers { diff --git a/src/TenantDatabaseManagers/PostgreSQLSchemaManager.php b/src/TenantDatabaseManagers/PostgreSQLSchemaManager.php index e2c2cf8c..cb5d17d0 100644 --- a/src/TenantDatabaseManagers/PostgreSQLSchemaManager.php +++ b/src/TenantDatabaseManagers/PostgreSQLSchemaManager.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Stancl\Tenancy\TenantDatabaseManagers; -use Illuminate\Contracts\Config\Repository; use Illuminate\Database\Connection; use Illuminate\Support\Facades\DB; use Stancl\Tenancy\Contracts\TenantDatabaseManager; diff --git a/src/TenantDatabaseManagers/SQLiteDatabaseManager.php b/src/TenantDatabaseManagers/SQLiteDatabaseManager.php index f4bdc85a..1b73f250 100644 --- a/src/TenantDatabaseManagers/SQLiteDatabaseManager.php +++ b/src/TenantDatabaseManagers/SQLiteDatabaseManager.php @@ -41,6 +41,6 @@ class SQLiteDatabaseManager implements TenantDatabaseManager public function setConnection(string $connection): void { - // + // } } diff --git a/src/helpers.php b/src/helpers.php index 44e5039f..9c3b75cd 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -2,8 +2,8 @@ declare(strict_types=1); -use Stancl\Tenancy\Tenancy; use Stancl\Tenancy\Contracts\Tenant; +use Stancl\Tenancy\Tenancy; if (! function_exists('tenancy')) { /** @return Tenancy */ @@ -23,7 +23,7 @@ if (! function_exists('tenant')) { function tenant($key = null) { if (! app()->bound(Tenant::class)) { - return null; + return; } if (is_null($key)) { diff --git a/tests/AutomaticModeTest.php b/tests/AutomaticModeTest.php index 344df129..c9d08879 100644 --- a/tests/AutomaticModeTest.php +++ b/tests/AutomaticModeTest.php @@ -1,15 +1,16 @@ instance('tenancy_ended', true); } -} \ No newline at end of file +} diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 88b76439..1b0c880d 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -1,5 +1,7 @@ [ - DatabaseTenancyBootstrapper::class + DatabaseTenancyBootstrapper::class, ]]); $tenant1 = Tenant::create(); @@ -78,7 +79,7 @@ class BootstrapperTest extends TestCase { config([ 'tenancy.bootstrappers' => [ - CacheTenancyBootstrapper::class + CacheTenancyBootstrapper::class, ], 'cache.default' => 'redis', ]); @@ -106,7 +107,7 @@ class BootstrapperTest extends TestCase $this->assertSame('xyz', Cache::get('foo')); tenancy()->initialize($tenant1); - + // Asset data didn't leak to original tenant $this->assertSame('bar', Cache::get('foo')); @@ -120,7 +121,7 @@ class BootstrapperTest extends TestCase public function redis_data_is_separated() { config(['tenancy.bootstrappers' => [ - RedisTenancyBootstrapper::class + RedisTenancyBootstrapper::class, ]]); $tenant1 = Tenant::create(); @@ -151,7 +152,7 @@ class BootstrapperTest extends TestCase public function filesystem_data_is_separated() { config(['tenancy.bootstrappers' => [ - FilesystemTenancyBootstrapper::class + FilesystemTenancyBootstrapper::class, ]]); $old_storage_path = storage_path(); diff --git a/tests/CacheManagerTest.php b/tests/CacheManagerTest.php index 97b53c9e..a54aaa67 100644 --- a/tests/CacheManagerTest.php +++ b/tests/CacheManagerTest.php @@ -5,11 +5,10 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; use Illuminate\Support\Facades\Event; -use Stancl\Tenancy\Tests\Etc\Tenant; -use Stancl\Tenancy\Listeners\BootstrapTenancy; -use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper; -use Stancl\Tenancy\Tests\TestCase; +use Stancl\Tenancy\Events\TenancyInitialized; +use Stancl\Tenancy\Listeners\BootstrapTenancy; +use Stancl\Tenancy\Tests\Etc\Tenant; class CacheManagerTest extends TestCase { @@ -20,7 +19,7 @@ class CacheManagerTest extends TestCase config(['tenancy.bootstrappers' => [ CacheTenancyBootstrapper::class, ]]); - + Event::listen(TenancyInitialized::class, BootstrapTenancy::class); } diff --git a/tests/CachedTenantResolverTest.php b/tests/CachedTenantResolverTest.php index 4a0ea8a8..8b81bcd3 100644 --- a/tests/CachedTenantResolverTest.php +++ b/tests/CachedTenantResolverTest.php @@ -1,5 +1,7 @@ assertTrue($tenant->is(app(CachedTenantResolver::class)->resolve(DomainTenantResolver::class, ['acme']))); } -} \ No newline at end of file +} diff --git a/tests/CombinedDomainAndSubdomainIdentificationTest.php b/tests/CombinedDomainAndSubdomainIdentificationTest.php index 6da2a963..6712458c 100644 --- a/tests/CombinedDomainAndSubdomainIdentificationTest.php +++ b/tests/CombinedDomainAndSubdomainIdentificationTest.php @@ -1,12 +1,13 @@ toListener()); config(['tenancy.bootstrappers' => [ - DatabaseTenancyBootstrapper::class + DatabaseTenancyBootstrapper::class, ]]); - + Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class); } @@ -70,9 +69,9 @@ class CommandsTest extends TestCase $this->assertFalse(Schema::hasTable('users')); Artisan::call('tenants:migrate'); $this->assertFalse(Schema::hasTable('users')); - + tenancy()->initialize($tenant); - + $this->assertTrue(Schema::hasTable('users')); } @@ -98,9 +97,9 @@ class CommandsTest extends TestCase $tenant = Tenant::create(); Artisan::call('tenants:migrate'); $this->assertFalse(Schema::hasTable('users')); - + tenancy()->initialize($tenant); - + $this->assertTrue(Schema::hasTable('users')); Artisan::call('tenants:rollback'); $this->assertFalse(Schema::hasTable('users')); @@ -178,9 +177,9 @@ class CommandsTest extends TestCase $this->assertFalse(Schema::hasTable('users')); Artisan::call('tenants:migrate-fresh'); $this->assertFalse(Schema::hasTable('users')); - + tenancy()->initialize($tenant); - + $this->assertTrue(Schema::hasTable('users')); $this->assertFalse(DB::table('users')->exists()); diff --git a/tests/DatabasePreparationTest.php b/tests/DatabasePreparationTest.php index fa601772..12d30059 100644 --- a/tests/DatabasePreparationTest.php +++ b/tests/DatabasePreparationTest.php @@ -1,5 +1,7 @@ 'Foo', 'email' => 'foo@bar.com', 'password' => 'secret']); }); } -} \ No newline at end of file +} diff --git a/tests/DatabaseUsersTest.php b/tests/DatabaseUsersTest.php index 6ee2af23..0b095024 100644 --- a/tests/DatabaseUsersTest.php +++ b/tests/DatabaseUsersTest.php @@ -7,18 +7,17 @@ namespace Stancl\Tenancy\Tests; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; use Illuminate\Support\Str; +use Stancl\JobPipeline\JobPipeline; +use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Contracts\ManagesDatabaseUsers; +use Stancl\Tenancy\Events\TenancyInitialized; +use Stancl\Tenancy\Events\TenantCreated; use Stancl\Tenancy\Exceptions\TenantDatabaseUserAlreadyExistsException; +use Stancl\Tenancy\Jobs\CreateDatabase; +use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\TenantDatabaseManagers\MySQLDatabaseManager; use Stancl\Tenancy\TenantDatabaseManagers\PermissionControlledMySQLDatabaseManager; use Stancl\Tenancy\Tests\Etc\Tenant; -use Stancl\Tenancy\Events\TenancyInitialized; -use Stancl\JobPipeline\JobPipeline; -use Stancl\Tenancy\Events\TenantCreated; -use Stancl\Tenancy\Jobs\CreateDatabase; -use Stancl\Tenancy\Listeners\BootstrapTenancy; -use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; -use Stancl\Tenancy\Tests\TestCase; class DatabaseUsersTest extends TestCase { diff --git a/tests/DomainTest.php b/tests/DomainTest.php index b7c15128..f793aad2 100644 --- a/tests/DomainTest.php +++ b/tests/DomainTest.php @@ -1,15 +1,16 @@ middleware([InitializeTenancyByDomain::class, CheckTenantForMaintenanceMode::class]); - + $tenant = MaintenanceTenant::create(); $tenant->domains()->create([ 'domain' => 'acme.localhost', @@ -39,4 +41,4 @@ class MaintenanceModeTest extends TestCase class MaintenanceTenant extends Tenant { use MaintenanceMode; -} \ No newline at end of file +} diff --git a/tests/PathIdentificationTest.php b/tests/PathIdentificationTest.php index 28211925..7a408ed0 100644 --- a/tests/PathIdentificationTest.php +++ b/tests/PathIdentificationTest.php @@ -1,14 +1,15 @@ expectException(TenantCouldNotBeIdentifiedByPathException::class); - $this + $this ->withoutExceptionHandling() ->get('/acme/foo/abc/xyz'); - + $this->assertFalse(tenancy()->initialized); } @@ -115,7 +116,6 @@ class PathIdentificationTest extends TestCase ->get('/bar/foo/bar'); } - /** @test */ public function tenant_parameter_name_can_be_customized() { diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 1631ab7c..41d71320 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -1,5 +1,7 @@ valuestore->put('tenant_id', "The current tenant id is: " . tenant('id')); + $this->valuestore->put('tenant_id', 'The current tenant id is: ' . tenant('id')); } } diff --git a/tests/RequestDataIdentificationTest.php b/tests/RequestDataIdentificationTest.php index 0007d26e..1f3cc459 100644 --- a/tests/RequestDataIdentificationTest.php +++ b/tests/RequestDataIdentificationTest.php @@ -5,9 +5,8 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; use Illuminate\Support\Facades\Route; -use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData; -use Stancl\Tenancy\Tests\TestCase; +use Stancl\Tenancy\Tests\Etc\Tenant; class RequestDataIdentificationTest extends TestCase { diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 2bd9415c..0df8b715 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -1,5 +1,7 @@ artisan('migrate', [ '--path' => [ __DIR__ . '/Etc/synced_resource_migrations', - __DIR__ . '/Etc/synced_resource_migrations/users' + __DIR__ . '/Etc/synced_resource_migrations/users', ], '--realpath' => true, ])->assertExitCode(0); @@ -506,7 +507,7 @@ class ResourceSyncingTest extends TestCase Event::assertDispatched(SyncedResourceChangedInForeignDatabase::class, function (SyncedResourceChangedInForeignDatabase $event) { return $event->tenant->getTenantKey() === 't1'; }); - + $centralUser->tenants()->attach('t2'); Event::assertDispatched(SyncedResourceChangedInForeignDatabase::class, function (SyncedResourceChangedInForeignDatabase $event) { return $event->tenant->getTenantKey() === 't2'; @@ -663,4 +664,4 @@ class ResourceUser extends Model implements Syncable 'email', ]; } -} \ No newline at end of file +} diff --git a/tests/ScopeSessionsTest.php b/tests/ScopeSessionsTest.php index 72559ad0..b5fb962a 100644 --- a/tests/ScopeSessionsTest.php +++ b/tests/ScopeSessionsTest.php @@ -1,5 +1,7 @@ expectException(TenancyNotInitializedException::class); $this->withoutExceptionHandling()->get('http://acme.localhost/bar'); } -} \ No newline at end of file +} diff --git a/tests/SingleDatabaseTenancyTest.php b/tests/SingleDatabaseTenancyTest.php index 33f08380..33a86fd3 100644 --- a/tests/SingleDatabaseTenancyTest.php +++ b/tests/SingleDatabaseTenancyTest.php @@ -1,14 +1,14 @@ initialize($acme = Tenant::create([ 'id' => 'acme', ])); - + Post::create(['text' => 'Foo', 'slug' => 'foo']); $data = ['text' => 'Foo 2', 'slug' => 'foo']; @@ -301,7 +301,7 @@ class SingleDatabaseTenancyTest extends TestCase $existsFails = Validator::make($data, [ 'slug' => 'exists:posts', ])->fails(); - + // Assert that 'unique' and 'exists' aren't scoped by default // $this->assertFalse($uniqueFails); // todo get these two assertions to pass. for some reason, the validator is passing for both 'unique' and 'exists' // $this->assertTrue($existsFails); // todo get these two assertions to pass. for some reason, the validator is passing for both 'unique' and 'exists' @@ -369,4 +369,4 @@ class GlobalResource extends Model { protected $guarded = []; public $timestamps = false; -} \ No newline at end of file +} diff --git a/tests/SubdomainTest.php b/tests/SubdomainTest.php index bae8f8ca..1ee1a20b 100644 --- a/tests/SubdomainTest.php +++ b/tests/SubdomainTest.php @@ -1,13 +1,14 @@ [ - FilesystemTenancyBootstrapper::class + FilesystemTenancyBootstrapper::class, ]]); - + Event::listen(TenancyInitialized::class, BootstrapTenancy::class); } diff --git a/tests/TenantAwareCommandTest.php b/tests/TenantAwareCommandTest.php index 0e62a1c7..b8d75aed 100644 --- a/tests/TenantAwareCommandTest.php +++ b/tests/TenantAwareCommandTest.php @@ -7,7 +7,6 @@ namespace Stancl\Tenancy\Tests; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Stancl\Tenancy\Tests\Etc\Tenant; -use Stancl\Tenancy\Tests\TestCase; class TenantAwareCommandTest extends TestCase { diff --git a/tests/TenantDatabaseManagerTest.php b/tests/TenantDatabaseManagerTest.php index 78675f78..fa4c9312 100644 --- a/tests/TenantDatabaseManagerTest.php +++ b/tests/TenantDatabaseManagerTest.php @@ -4,25 +4,23 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; -use Stancl\Tenancy\Tests\Etc\Tenant; -use Stancl\Tenancy\DatabaseManager; -use Stancl\Tenancy\Listeners\BootstrapTenancy; +use Illuminate\Support\Str; +use PDO; use Stancl\JobPipeline\JobPipeline; +use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; +use Stancl\Tenancy\DatabaseManager; use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Events\TenantCreated; use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException; use Stancl\Tenancy\Jobs\CreateDatabase; -use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; +use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\TenantDatabaseManagers\MySQLDatabaseManager; use Stancl\Tenancy\TenantDatabaseManagers\PermissionControlledMySQLDatabaseManager; use Stancl\Tenancy\TenantDatabaseManagers\PostgreSQLDatabaseManager; use Stancl\Tenancy\TenantDatabaseManagers\PostgreSQLSchemaManager; use Stancl\Tenancy\TenantDatabaseManagers\SQLiteDatabaseManager; -use Stancl\Tenancy\Tests\TestCase; -use Illuminate\Support\Str; -use PDO; +use Stancl\Tenancy\Tests\Etc\Tenant; class TenantDatabaseManagerTest extends TestCase { diff --git a/tests/TenantModelTest.php b/tests/TenantModelTest.php index 8d358990..44c262eb 100644 --- a/tests/TenantModelTest.php +++ b/tests/TenantModelTest.php @@ -1,5 +1,7 @@ assertTrue(tenant() instanceof MyTenant); } - + /** @test */ public function custom_tenant_model_that_doesnt_extend_vendor_Tenant_model_can_be_used() { @@ -143,7 +144,7 @@ class TenantModelTest extends TestCase public function tenant_can_be_created_even_when_we_are_in_another_tenants_context() { config(['tenancy.bootstrappers' => [ - DatabaseTenancyBootstrapper::class + DatabaseTenancyBootstrapper::class, ]]); Event::listen(TenancyInitialized::class, BootstrapTenancy::class); diff --git a/tests/TenantUserImpersonationTest.php b/tests/TenantUserImpersonationTest.php index 8937728e..c5e83853 100644 --- a/tests/TenantUserImpersonationTest.php +++ b/tests/TenantUserImpersonationTest.php @@ -1,29 +1,31 @@ get('http://foo.localhost/impersonate/' . $token->token) ->assertSuccessful() ->assertSee('You are logged in as Joe'); - + $this->assertNull(ImpersonationToken::find($token->token)); }