diff --git a/src/Bootstrappers/FilesystemTenancyBootstrapper.php b/src/Bootstrappers/FilesystemTenancyBootstrapper.php index 2b4f8dfe..6f720e7c 100644 --- a/src/Bootstrappers/FilesystemTenancyBootstrapper.php +++ b/src/Bootstrappers/FilesystemTenancyBootstrapper.php @@ -69,7 +69,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper if (! $finalPrefix) { $finalPrefix = $originalRoot - ? rtrim($originalRoot, '/') . '/'. $suffix + ? rtrim($originalRoot, '/') . '/' . $suffix : $suffix; } diff --git a/src/Bootstrappers/QueueTenancyBootstrapper.php b/src/Bootstrappers/QueueTenancyBootstrapper.php index 790e1344..2f859ecd 100644 --- a/src/Bootstrappers/QueueTenancyBootstrapper.php +++ b/src/Bootstrappers/QueueTenancyBootstrapper.php @@ -4,18 +4,17 @@ declare(strict_types=1); namespace Stancl\Tenancy\Bootstrappers; -use Illuminate\Support\Str; use Illuminate\Config\Repository; -use Illuminate\Queue\QueueManager; -use Stancl\Tenancy\Contracts\Tenant; +use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\Foundation\Application; use Illuminate\Queue\Events\JobFailed; use Illuminate\Queue\Events\JobProcessed; use Illuminate\Queue\Events\JobProcessing; -use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Queue\Events\JobRetryRequested; +use Illuminate\Queue\QueueManager; use Illuminate\Support\Testing\Fakes\QueueFake; -use Illuminate\Contracts\Foundation\Application; use Stancl\Tenancy\Contracts\TenancyBootstrapper; +use Stancl\Tenancy\Contracts\Tenant; class QueueTenancyBootstrapper implements TenancyBootstrapper { diff --git a/src/CacheManager.php b/src/CacheManager.php index 88428353..777a142f 100644 --- a/src/CacheManager.php +++ b/src/CacheManager.php @@ -21,7 +21,7 @@ class CacheManager extends BaseCacheManager if ($method === 'tags') { $count = count($parameters); - + if ($count !== 1) { throw new \Exception("Method tags() takes exactly 1 argument. $count passed."); } diff --git a/src/Commands/TenantDump.php b/src/Commands/TenantDump.php index 557c6975..9c8698c6 100644 --- a/src/Commands/TenantDump.php +++ b/src/Commands/TenantDump.php @@ -21,10 +21,9 @@ class TenantDump extends DumpCommand $this->specifyParameters(); } - public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int { - $this->tenant()->run(fn() => parent::handle($connections, $dispatcher)); + $this->tenant()->run(fn () => parent::handle($connections, $dispatcher)); return Command::SUCCESS; } diff --git a/src/Concerns/ExtendsLaravelCommand.php b/src/Concerns/ExtendsLaravelCommand.php index bdafc8f7..d08ad6b6 100644 --- a/src/Concerns/ExtendsLaravelCommand.php +++ b/src/Concerns/ExtendsLaravelCommand.php @@ -1,5 +1,7 @@ model->getCentralModelName() - ::where($event->model->getGlobalIdentifierKeyName(), $event->model->getGlobalIdentifierKey()) + $centralModel = $event->model->getCentralModelName()::where($event->model->getGlobalIdentifierKeyName(), $event->model->getGlobalIdentifierKey()) ->first(); // We disable events for this call, to avoid triggering this event & listener again. diff --git a/src/Middleware/CheckTenantForMaintenanceMode.php b/src/Middleware/CheckTenantForMaintenanceMode.php index 8e29a31e..c1c734f5 100644 --- a/src/Middleware/CheckTenantForMaintenanceMode.php +++ b/src/Middleware/CheckTenantForMaintenanceMode.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace Stancl\Tenancy\Middleware; use Closure; -use Symfony\Component\HttpKernel\Exception\HttpException; use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode; use Stancl\Tenancy\Exceptions\TenancyNotInitializedException; use Symfony\Component\HttpFoundation\IpUtils; +use Symfony\Component\HttpKernel\Exception\HttpException; class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode { diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 588fadd8..a0320282 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -5,26 +5,26 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; use Illuminate\Filesystem\FilesystemAdapter; -use ReflectionObject; -use ReflectionProperty; -use Illuminate\Support\Str; -use Illuminate\Support\Facades\DB; -use Stancl\JobPipeline\JobPipeline; -use Stancl\Tenancy\Tests\Etc\Tenant; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Storage; -use Stancl\Tenancy\Events\TenancyEnded; -use Stancl\Tenancy\Jobs\CreateDatabase; -use Stancl\Tenancy\Events\TenantCreated; -use Stancl\Tenancy\Events\TenancyInitialized; -use Stancl\Tenancy\Listeners\BootstrapTenancy; -use Stancl\Tenancy\Listeners\RevertToCentralContext; +use Illuminate\Support\Str; +use ReflectionObject; +use ReflectionProperty; +use Stancl\JobPipeline\JobPipeline; use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper; -use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper; +use Stancl\Tenancy\Events\TenancyEnded; +use Stancl\Tenancy\Events\TenancyInitialized; +use Stancl\Tenancy\Events\TenantCreated; +use Stancl\Tenancy\Jobs\CreateDatabase; +use Stancl\Tenancy\Listeners\BootstrapTenancy; +use Stancl\Tenancy\Listeners\RevertToCentralContext; +use Stancl\Tenancy\Tests\Etc\Tenant; class BootstrapperTest extends TestCase { diff --git a/tests/Etc/ExampleSeeder.php b/tests/Etc/ExampleSeeder.php index a3e36123..2f97787e 100644 --- a/tests/Etc/ExampleSeeder.php +++ b/tests/Etc/ExampleSeeder.php @@ -19,7 +19,7 @@ class ExampleSeeder extends Seeder { DB::table('users')->insert([ 'name' => Str::random(10), - 'email' => Str::random(10).'@gmail.com', + 'email' => Str::random(10) . '@gmail.com', 'password' => bcrypt('password'), ]); } diff --git a/tests/EventListenerTest.php b/tests/EventListenerTest.php index 4a45205c..02ed8b3b 100644 --- a/tests/EventListenerTest.php +++ b/tests/EventListenerTest.php @@ -20,7 +20,6 @@ use Stancl\Tenancy\Jobs\CreateDatabase; use Stancl\Tenancy\Jobs\MigrateDatabase; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\QueueableListener; -use Stancl\Tenancy\Tenancy; use Stancl\Tenancy\Tests\Etc\Tenant; class EventListenerTest extends TestCase diff --git a/tests/MaintenanceModeTest.php b/tests/MaintenanceModeTest.php index 4a8d8d0c..90232932 100644 --- a/tests/MaintenanceModeTest.php +++ b/tests/MaintenanceModeTest.php @@ -4,14 +4,12 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; -use Symfony\Component\HttpKernel\Exception\HttpException; -use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException; use Illuminate\Support\Facades\Route; use Stancl\Tenancy\Database\Concerns\MaintenanceMode; use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Tests\Etc\Tenant; -use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; class MaintenanceModeTest extends TestCase { diff --git a/tests/QueueTest.php b/tests/QueueTest.php index a3df9cd7..fe34ba92 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -4,33 +4,31 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; -use Closure; use Exception; -use Illuminate\Support\Str; use Illuminate\Bus\Queueable; -use Spatie\Valuestore\Valuestore; -use Illuminate\Support\Facades\DB; -use Stancl\Tenancy\Tests\Etc\User; -use Stancl\JobPipeline\JobPipeline; -use Stancl\Tenancy\Tests\Etc\Tenant; -use Illuminate\Support\Facades\Event; -use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Schema; -use Stancl\Tenancy\Events\TenancyEnded; -use Stancl\Tenancy\Jobs\CreateDatabase; -use Illuminate\Queue\InteractsWithQueue; -use Stancl\Tenancy\Events\TenantCreated; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\Events\JobProcessed; use Illuminate\Queue\Events\JobProcessing; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Foundation\Bus\Dispatchable; -use PDO; +use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Str; +use Spatie\Valuestore\Valuestore; +use Stancl\JobPipeline\JobPipeline; +use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; +use Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper; +use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Events\TenancyInitialized; +use Stancl\Tenancy\Events\TenantCreated; +use Stancl\Tenancy\Jobs\CreateDatabase; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; -use Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper; -use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; +use Stancl\Tenancy\Tests\Etc\Tenant; +use Stancl\Tenancy\Tests\Etc\User; class QueueTest extends TestCase { diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 570448d1..0ff95a52 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -589,7 +589,9 @@ class CentralUser extends Model implements SyncMaster use ResourceSyncing, CentralConnection; protected $guarded = []; + public $timestamps = false; + public $table = 'users'; public function tenants(): BelongsToMany @@ -633,7 +635,9 @@ class ResourceUser extends Model implements Syncable use ResourceSyncing; protected $table = 'users'; + protected $guarded = []; + public $timestamps = false; public function getGlobalIdentifierKey() diff --git a/tests/SingleDatabaseTenancyTest.php b/tests/SingleDatabaseTenancyTest.php index b64478cc..d0425dd9 100644 --- a/tests/SingleDatabaseTenancyTest.php +++ b/tests/SingleDatabaseTenancyTest.php @@ -329,6 +329,7 @@ class Post extends Model use BelongsToTenant; protected $guarded = []; + public $timestamps = false; public function comments() @@ -345,6 +346,7 @@ class Post extends Model class Comment extends Model { protected $guarded = []; + public $timestamps = false; public function post() @@ -368,5 +370,6 @@ class ScopedComment extends Comment class GlobalResource extends Model { protected $guarded = []; + public $timestamps = false; } diff --git a/tests/TenantDatabaseManagerTest.php b/tests/TenantDatabaseManagerTest.php index 0e1464c0..12273c85 100644 --- a/tests/TenantDatabaseManagerTest.php +++ b/tests/TenantDatabaseManagerTest.php @@ -104,7 +104,7 @@ class TenantDatabaseManagerTest extends TestCase ['sqlite', SQLiteDatabaseManager::class], ['pgsql', PostgreSQLDatabaseManager::class], ['pgsql', PostgreSQLSchemaManager::class], - ['sqlsrv', MicrosoftSQLDatabaseManager::class] + ['sqlsrv', MicrosoftSQLDatabaseManager::class], ]; } @@ -196,7 +196,7 @@ class TenantDatabaseManagerTest extends TestCase ]); tenancy()->initialize($tenant); - $schemaConfig = version_compare(app()->version(), '9.0', '>=') ? + $schemaConfig = version_compare(app()->version(), '9.0', '>=') ? config('database.connections.' . config('database.default') . '.search_path') : config('database.connections.' . config('database.default') . '.schema'); diff --git a/tests/TenantModelTest.php b/tests/TenantModelTest.php index 46dc6a00..2d46c233 100644 --- a/tests/TenantModelTest.php +++ b/tests/TenantModelTest.php @@ -172,6 +172,7 @@ class MyTenant extends Tenant class AnotherTenant extends Model implements Contracts\Tenant { protected $guarded = []; + protected $table = 'tenants'; public function getTenantKeyName(): string diff --git a/tests/TenantUserImpersonationTest.php b/tests/TenantUserImpersonationTest.php index c5e83853..b50db84b 100644 --- a/tests/TenantUserImpersonationTest.php +++ b/tests/TenantUserImpersonationTest.php @@ -274,11 +274,13 @@ class TenantUserImpersonationTest extends TestCase class ImpersonationUser extends Authenticable { protected $guarded = []; + protected $table = 'users'; } class AnotherImpersonationUser extends Authenticable { protected $guarded = []; + protected $table = 'users'; }