From 97ab483173b38d9233082b349a9f73f268784449 Mon Sep 17 00:00:00 2001 From: Abrar Ahmad Date: Wed, 20 Jul 2022 18:28:45 +0500 Subject: [PATCH] Completing PR #881 (#902) * install PHP CS Fixer * Fix styling * remove StyleCI config * use config from archtechx/template * Fix styling * added `php-cs-fixer` * Update .php-cs-fixer.php * added GitHub token * Update ci.yml * Update ci.yml * Update ci.yml * php-cs-fixer workflow same as template Co-authored-by: Erik Gaal Co-authored-by: erikgaal --- .github/workflows/ci.yml | 18 +++ .gitignore | 1 + .php-cs-fixer.php | 141 ++++++++++++++++++ .styleci.yml | 7 - .../FilesystemTenancyBootstrapper.php | 2 +- .../QueueTenancyBootstrapper.php | 9 +- src/CacheManager.php | 3 +- src/Commands/Install.php | 2 - src/Commands/Migrate.php | 2 - src/Commands/MigrateFresh.php | 2 - src/Commands/Rollback.php | 2 - src/Commands/Run.php | 2 - src/Commands/Seed.php | 2 - src/Commands/TenantDump.php | 3 +- src/Commands/TenantList.php | 2 - src/Concerns/ExtendsLaravelCommand.php | 2 + src/Concerns/HasATenantsOption.php | 2 +- src/Contracts/TenantDatabaseManager.php | 10 -- src/Database/Concerns/TenantRun.php | 3 - src/Database/Models/ImpersonationToken.php | 5 + src/Database/Models/Tenant.php | 2 + src/DatabaseConfig.php | 5 +- src/Features/UserImpersonation.php | 1 - src/Listeners/UpdateSyncedResource.php | 3 +- .../CheckTenantForMaintenanceMode.php | 2 +- src/Middleware/InitializeTenancyByDomain.php | 6 +- .../InitializeTenancyByDomainOrSubdomain.php | 2 - src/Middleware/InitializeTenancyByPath.php | 4 +- .../InitializeTenancyByRequestData.php | 2 - .../InitializeTenancyBySubdomain.php | 2 - .../Contracts/CachedTenantResolver.php | 1 - src/Tenancy.php | 5 - src/TenancyServiceProvider.php | 4 - tests/BootstrapperTest.php | 26 ++-- tests/Etc/ExampleSeeder.php | 2 +- tests/EventListenerTest.php | 1 - tests/MaintenanceModeTest.php | 4 +- tests/QueueTest.php | 36 +++-- tests/ResourceSyncingTest.php | 4 + tests/SingleDatabaseTenancyTest.php | 3 + tests/TenantDatabaseManagerTest.php | 4 +- tests/TenantModelTest.php | 1 + tests/TenantUserImpersonationTest.php | 2 + 43 files changed, 231 insertions(+), 111 deletions(-) create mode 100644 .php-cs-fixer.php delete mode 100644 .styleci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81d37af5..3cbda814 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,8 @@ name: CI env: COMPOSE_INTERACTIVE_NO_CLI: 1 + PHP_CS_FIXER_IGNORE_ENV: 1 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} on: push: @@ -26,3 +28,19 @@ jobs: run: docker-compose exec -T test composer require --no-interaction "laravel/framework:${{ matrix.laravel }}" - name: Run tests run: ./test + + php-cs-fixer: + name: Code style (php-cs-fixer) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install php-cs-fixer + run: composer global require friendsofphp/php-cs-fixer + - name: Run php-cs-fixer + run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php + - name: Commit changes from php-cs-fixer + uses: EndBug/add-and-commit@v5 + with: + author_name: "PHP CS Fixer" + author_email: "phpcsfixer@example.com" + message: Fix code style (php-cs-fixer) diff --git a/.gitignore b/.gitignore index 95522c34..64d9dc21 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ clover.xml tenant-schema-test.dump tests/Etc/tmp/queuetest.json docker-compose.override.yml +.php-cs-fixer.cache diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 00000000..589838bc --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,141 @@ + ['syntax' => 'short'], + 'binary_operator_spaces' => [ + 'default' => 'single_space', + 'operators' => [ + '=>' => null, + '|' => 'no_space', + ] + ], + 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => true, + 'no_superfluous_phpdoc_tags' => true, + 'blank_line_before_statement' => [ + 'statements' => ['return'] + ], + 'braces' => true, + 'cast_spaces' => true, + 'class_definition' => true, + 'concat_space' => [ + 'spacing' => 'one' + ], + 'declare_equal_normalize' => true, + 'elseif' => true, + 'encoding' => true, + 'full_opening_tag' => true, + 'declare_strict_types' => true, + 'fully_qualified_strict_types' => true, // added by Shift + 'function_declaration' => true, + 'function_typehint_space' => true, + 'heredoc_to_nowdoc' => true, + 'include' => true, + 'increment_style' => ['style' => 'post'], + 'indentation_type' => true, + 'linebreak_after_opening_tag' => true, + 'line_ending' => true, + 'lowercase_cast' => true, + 'constant_case' => true, + 'lowercase_keywords' => true, + 'lowercase_static_reference' => true, // added from Symfony + 'magic_method_casing' => true, // added from Symfony + 'magic_constant_casing' => true, + 'method_argument_space' => true, + 'native_function_casing' => true, + 'no_alias_functions' => true, + 'no_extra_blank_lines' => [ + 'tokens' => [ + 'extra', + 'throw', + 'use', + 'use_trait', + ] + ], + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_closing_tag' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => [ + 'use' => 'echo' + ], + 'no_multiline_whitespace_around_double_arrow' => true, + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'no_multi_line' + ], + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => true, + 'no_spaces_inside_parenthesis' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'not_operator_with_successor_space' => true, + 'object_operator_without_whitespace' => true, + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'phpdoc_indent' => true, + 'general_phpdoc_tag_rename' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_scalar' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => true, + 'phpdoc_to_comment' => false, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'phpdoc_var_without_name' => true, + 'psr_autoloading' => true, + 'self_accessor' => true, + 'short_scalar_cast' => true, + 'simplified_null_return' => false, // disabled by Shift + 'single_blank_line_at_eof' => true, + 'single_blank_line_before_namespace' => true, + 'single_class_element_per_statement' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'no_unused_imports' => true, + 'single_line_comment_style' => [ + 'comment_types' => ['hash'] + ], + 'single_quote' => true, + 'space_after_semicolon' => true, + 'standardize_not_equals' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'whitespace_after_comma_in_array' => true, +]; + +$project_path = getcwd(); +$finder = Finder::create() + ->in([ + $project_path . '/src', + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return (new Config()) + ->setFinder($finder) + ->setRules($rules) + ->setRiskyAllowed(true) + ->setUsingCache(true); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index e6d2b2c1..00000000 --- a/.styleci.yml +++ /dev/null @@ -1,7 +0,0 @@ -risky: true -preset: laravel -enabled: -- declare_strict_types -disabled: -- concat_without_spaces -- ternary_operator_spaces 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..09581201 100644 --- a/src/CacheManager.php +++ b/src/CacheManager.php @@ -13,7 +13,6 @@ class CacheManager extends BaseCacheManager * * @param string $method * @param array $parameters - * @return mixed */ public function __call($method, $parameters) { @@ -21,7 +20,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/Install.php b/src/Commands/Install.php index dd2dd280..41492b26 100644 --- a/src/Commands/Install.php +++ b/src/Commands/Install.php @@ -24,8 +24,6 @@ class Install extends Command /** * Execute the console command. - * - * @return mixed */ public function handle() { diff --git a/src/Commands/Migrate.php b/src/Commands/Migrate.php index c67d3598..52ecd47f 100644 --- a/src/Commands/Migrate.php +++ b/src/Commands/Migrate.php @@ -33,8 +33,6 @@ class Migrate extends MigrateCommand /** * Execute the console command. - * - * @return mixed */ public function handle() { diff --git a/src/Commands/MigrateFresh.php b/src/Commands/MigrateFresh.php index 283d70b0..63860153 100644 --- a/src/Commands/MigrateFresh.php +++ b/src/Commands/MigrateFresh.php @@ -31,8 +31,6 @@ final class MigrateFresh extends Command /** * Execute the console command. - * - * @return mixed */ public function handle() { diff --git a/src/Commands/Rollback.php b/src/Commands/Rollback.php index e60d974b..1c434189 100644 --- a/src/Commands/Rollback.php +++ b/src/Commands/Rollback.php @@ -42,8 +42,6 @@ class Rollback extends RollbackCommand /** * Execute the console command. - * - * @return mixed */ public function handle() { diff --git a/src/Commands/Run.php b/src/Commands/Run.php index aa518d7a..2b20d9c3 100644 --- a/src/Commands/Run.php +++ b/src/Commands/Run.php @@ -27,8 +27,6 @@ class Run extends Command /** * Execute the console command. - * - * @return mixed */ public function handle() { diff --git a/src/Commands/Seed.php b/src/Commands/Seed.php index dc97ae71..8c525208 100644 --- a/src/Commands/Seed.php +++ b/src/Commands/Seed.php @@ -35,8 +35,6 @@ class Seed extends SeedCommand /** * Execute the console command. - * - * @return mixed */ public function handle() { 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/Commands/TenantList.php b/src/Commands/TenantList.php index d01afcb9..13775676 100644 --- a/src/Commands/TenantList.php +++ b/src/Commands/TenantList.php @@ -25,8 +25,6 @@ class TenantList extends Command /** * Execute the console command. - * - * @return mixed */ public function handle() { 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 @@ manager()->makeConnectionConfig( - array_merge($templateConnection, $this->tenantConfig()), $this->getName() + array_merge($templateConnection, $this->tenantConfig()), + $this->getName() ); } diff --git a/src/Features/UserImpersonation.php b/src/Features/UserImpersonation.php index 48d65bb9..f96465ff 100644 --- a/src/Features/UserImpersonation.php +++ b/src/Features/UserImpersonation.php @@ -33,7 +33,6 @@ class UserImpersonation implements Feature * * @param string|ImpersonationToken $token * @param int $ttl - * @return RedirectResponse */ public static function makeResponse($token, int $ttl = null): RedirectResponse { diff --git a/src/Listeners/UpdateSyncedResource.php b/src/Listeners/UpdateSyncedResource.php index 40d4d644..9be290f0 100644 --- a/src/Listeners/UpdateSyncedResource.php +++ b/src/Listeners/UpdateSyncedResource.php @@ -48,8 +48,7 @@ class UpdateSyncedResource extends QueueableListener protected function updateResourceInCentralDatabaseAndGetTenants($event, $syncedAttributes) { /** @var Model|SyncMaster $centralModel */ - $centralModel = $event->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/src/Middleware/InitializeTenancyByDomain.php b/src/Middleware/InitializeTenancyByDomain.php index 24a1abb7..5a07112d 100644 --- a/src/Middleware/InitializeTenancyByDomain.php +++ b/src/Middleware/InitializeTenancyByDomain.php @@ -29,13 +29,13 @@ class InitializeTenancyByDomain extends IdentificationMiddleware * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle($request, Closure $next) { return $this->initializeTenancy( - $request, $next, $request->getHost() + $request, + $next, + $request->getHost() ); } } diff --git a/src/Middleware/InitializeTenancyByDomainOrSubdomain.php b/src/Middleware/InitializeTenancyByDomainOrSubdomain.php index 94217bba..9b153db3 100644 --- a/src/Middleware/InitializeTenancyByDomainOrSubdomain.php +++ b/src/Middleware/InitializeTenancyByDomainOrSubdomain.php @@ -13,8 +13,6 @@ class InitializeTenancyByDomainOrSubdomain * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle($request, Closure $next) { diff --git a/src/Middleware/InitializeTenancyByPath.php b/src/Middleware/InitializeTenancyByPath.php index 6289199b..e66400c5 100644 --- a/src/Middleware/InitializeTenancyByPath.php +++ b/src/Middleware/InitializeTenancyByPath.php @@ -38,7 +38,9 @@ class InitializeTenancyByPath extends IdentificationMiddleware // simply injected into some route controller action. if ($route->parameterNames()[0] === PathTenantResolver::$tenantParameterName) { return $this->initializeTenancy( - $request, $next, $route + $request, + $next, + $route ); } else { throw new RouteIsMissingTenantParameterException; diff --git a/src/Middleware/InitializeTenancyByRequestData.php b/src/Middleware/InitializeTenancyByRequestData.php index de75d8c5..4e1d33ff 100644 --- a/src/Middleware/InitializeTenancyByRequestData.php +++ b/src/Middleware/InitializeTenancyByRequestData.php @@ -36,8 +36,6 @@ class InitializeTenancyByRequestData extends IdentificationMiddleware * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle($request, Closure $next) { diff --git a/src/Middleware/InitializeTenancyBySubdomain.php b/src/Middleware/InitializeTenancyBySubdomain.php index 55d76b05..76389df7 100644 --- a/src/Middleware/InitializeTenancyBySubdomain.php +++ b/src/Middleware/InitializeTenancyBySubdomain.php @@ -28,8 +28,6 @@ class InitializeTenancyBySubdomain extends InitializeTenancyByDomain * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle($request, Closure $next) { diff --git a/src/Resolvers/Contracts/CachedTenantResolver.php b/src/Resolvers/Contracts/CachedTenantResolver.php index 968ac794..e84f1fb1 100644 --- a/src/Resolvers/Contracts/CachedTenantResolver.php +++ b/src/Resolvers/Contracts/CachedTenantResolver.php @@ -75,7 +75,6 @@ abstract class CachedTenantResolver implements TenantResolver /** * Get all the arg combinations for resolve() that can be used to find this tenant. * - * @param Tenant $tenant * @return array[] */ abstract public function getArgsForTenant(Tenant $tenant): array; diff --git a/src/Tenancy.php b/src/Tenancy.php index 30f138e3..6873f93b 100644 --- a/src/Tenancy.php +++ b/src/Tenancy.php @@ -27,7 +27,6 @@ class Tenancy /** * Initializes the tenant. * @param Tenant|int|string $tenant - * @return void */ public function initialize($tenant): void { @@ -106,9 +105,6 @@ class Tenancy /** * Run a callback in the central context. * Atomic, safely reverts to previous context. - * - * @param callable $callback - * @return mixed */ public function central(callable $callback) { @@ -132,7 +128,6 @@ class Tenancy * More performant than running $tenant->run() one by one. * * @param Tenant[]|\Traversable|string[]|null $tenants - * @param callable $callback * @return void */ public function runForMultiple($tenants, callable $callback) diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index dd061af3..e23200a6 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -15,8 +15,6 @@ class TenancyServiceProvider extends ServiceProvider { /** * Register services. - * - * @return void */ public function register(): void { @@ -76,8 +74,6 @@ class TenancyServiceProvider extends ServiceProvider /** * Bootstrap services. - * - * @return void */ public function boot(): void { 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'; }