1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 15:34:03 +00:00

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 <me@erikgaal.nl>
Co-authored-by: erikgaal <erikgaal@users.noreply.github.com>
This commit is contained in:
Abrar Ahmad 2022-07-20 18:28:45 +05:00 committed by GitHub
parent 627233d07a
commit 97ab483173
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 231 additions and 111 deletions

View file

@ -2,6 +2,8 @@ name: CI
env: env:
COMPOSE_INTERACTIVE_NO_CLI: 1 COMPOSE_INTERACTIVE_NO_CLI: 1
PHP_CS_FIXER_IGNORE_ENV: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on: on:
push: push:
@ -26,3 +28,19 @@ jobs:
run: docker-compose exec -T test composer require --no-interaction "laravel/framework:${{ matrix.laravel }}" run: docker-compose exec -T test composer require --no-interaction "laravel/framework:${{ matrix.laravel }}"
- name: Run tests - name: Run tests
run: ./test 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)

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ clover.xml
tenant-schema-test.dump tenant-schema-test.dump
tests/Etc/tmp/queuetest.json tests/Etc/tmp/queuetest.json
docker-compose.override.yml docker-compose.override.yml
.php-cs-fixer.cache

141
.php-cs-fixer.php Normal file
View file

@ -0,0 +1,141 @@
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$rules = [
'array_syntax' => ['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);

View file

@ -1,7 +0,0 @@
risky: true
preset: laravel
enabled:
- declare_strict_types
disabled:
- concat_without_spaces
- ternary_operator_spaces

View file

@ -69,7 +69,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
if (! $finalPrefix) { if (! $finalPrefix) {
$finalPrefix = $originalRoot $finalPrefix = $originalRoot
? rtrim($originalRoot, '/') . '/'. $suffix ? rtrim($originalRoot, '/') . '/' . $suffix
: $suffix; : $suffix;
} }

View file

@ -4,18 +4,17 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers; namespace Stancl\Tenancy\Bootstrappers;
use Illuminate\Support\Str;
use Illuminate\Config\Repository; use Illuminate\Config\Repository;
use Illuminate\Queue\QueueManager; use Illuminate\Contracts\Events\Dispatcher;
use Stancl\Tenancy\Contracts\Tenant; use Illuminate\Contracts\Foundation\Application;
use Illuminate\Queue\Events\JobFailed; use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed; use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing; use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Queue\Events\JobRetryRequested; use Illuminate\Queue\Events\JobRetryRequested;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Testing\Fakes\QueueFake; use Illuminate\Support\Testing\Fakes\QueueFake;
use Illuminate\Contracts\Foundation\Application;
use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
class QueueTenancyBootstrapper implements TenancyBootstrapper class QueueTenancyBootstrapper implements TenancyBootstrapper
{ {

View file

@ -13,7 +13,6 @@ class CacheManager extends BaseCacheManager
* *
* @param string $method * @param string $method
* @param array $parameters * @param array $parameters
* @return mixed
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
{ {

View file

@ -24,8 +24,6 @@ class Install extends Command
/** /**
* Execute the console command. * Execute the console command.
*
* @return mixed
*/ */
public function handle() public function handle()
{ {

View file

@ -33,8 +33,6 @@ class Migrate extends MigrateCommand
/** /**
* Execute the console command. * Execute the console command.
*
* @return mixed
*/ */
public function handle() public function handle()
{ {

View file

@ -31,8 +31,6 @@ final class MigrateFresh extends Command
/** /**
* Execute the console command. * Execute the console command.
*
* @return mixed
*/ */
public function handle() public function handle()
{ {

View file

@ -42,8 +42,6 @@ class Rollback extends RollbackCommand
/** /**
* Execute the console command. * Execute the console command.
*
* @return mixed
*/ */
public function handle() public function handle()
{ {

View file

@ -27,8 +27,6 @@ class Run extends Command
/** /**
* Execute the console command. * Execute the console command.
*
* @return mixed
*/ */
public function handle() public function handle()
{ {

View file

@ -35,8 +35,6 @@ class Seed extends SeedCommand
/** /**
* Execute the console command. * Execute the console command.
*
* @return mixed
*/ */
public function handle() public function handle()
{ {

View file

@ -21,10 +21,9 @@ class TenantDump extends DumpCommand
$this->specifyParameters(); $this->specifyParameters();
} }
public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int 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; return Command::SUCCESS;
} }

View file

@ -25,8 +25,6 @@ class TenantList extends Command
/** /**
* Execute the console command. * Execute the console command.
*
* @return mixed
*/ */
public function handle() public function handle()
{ {

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Stancl\Tenancy\Concerns; namespace Stancl\Tenancy\Concerns;
trait ExtendsLaravelCommand trait ExtendsLaravelCommand

View file

@ -12,7 +12,7 @@ trait HasATenantsOption
protected function getOptions() protected function getOptions()
{ {
return array_merge([ return array_merge([
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null], ['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, '', null],
], parent::getOptions()); ], parent::getOptions());
} }

View file

@ -20,18 +20,11 @@ interface TenantDatabaseManager
/** /**
* Does a database exist. * Does a database exist.
*
* @param string $name
* @return bool
*/ */
public function databaseExists(string $name): bool; public function databaseExists(string $name): bool;
/** /**
* Make a DB connection config array. * Make a DB connection config array.
*
* @param array $baseConfig
* @param string $databaseName
* @return array
*/ */
public function makeConnectionConfig(array $baseConfig, string $databaseName): array; public function makeConnectionConfig(array $baseConfig, string $databaseName): array;
@ -39,9 +32,6 @@ interface TenantDatabaseManager
* Set the DB connection that should be used by the tenant database manager. * Set the DB connection that should be used by the tenant database manager.
* *
* @throws NoConnectionSetException * @throws NoConnectionSetException
*
* @param string $connection
* @return void
*/ */
public function setConnection(string $connection): void; public function setConnection(string $connection): void;
} }

View file

@ -11,9 +11,6 @@ trait TenantRun
/** /**
* Run a callback in this tenant's context. * Run a callback in this tenant's context.
* Atomic, safely reverts to previous context. * Atomic, safely reverts to previous context.
*
* @param callable $callback
* @return mixed
*/ */
public function run(callable $callback) public function run(callable $callback)
{ {

View file

@ -22,10 +22,15 @@ class ImpersonationToken extends Model
use CentralConnection; use CentralConnection;
protected $guarded = []; protected $guarded = [];
public $timestamps = false; public $timestamps = false;
protected $primaryKey = 'token'; protected $primaryKey = 'token';
public $incrementing = false; public $incrementing = false;
protected $table = 'tenant_user_impersonation_tokens'; protected $table = 'tenant_user_impersonation_tokens';
protected $dates = [ protected $dates = [
'created_at', 'created_at',
]; ];

View file

@ -29,7 +29,9 @@ class Tenant extends Model implements Contracts\Tenant
Concerns\InvalidatesResolverCache; Concerns\InvalidatesResolverCache;
protected $table = 'tenants'; protected $table = 'tenants';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $guarded = []; protected $guarded = [];
public function getTenantKeyName(): string public function getTenantKeyName(): string

View file

@ -80,8 +80,6 @@ class DatabaseConfig
/** /**
* Generate DB name, username & password and write them to the tenant model. * Generate DB name, username & password and write them to the tenant model.
*
* @return void
*/ */
public function makeCredentials(): void public function makeCredentials(): void
{ {
@ -113,7 +111,8 @@ class DatabaseConfig
$templateConnection = config("database.connections.{$template}"); $templateConnection = config("database.connections.{$template}");
return $this->manager()->makeConnectionConfig( return $this->manager()->makeConnectionConfig(
array_merge($templateConnection, $this->tenantConfig()), $this->getName() array_merge($templateConnection, $this->tenantConfig()),
$this->getName()
); );
} }

View file

@ -33,7 +33,6 @@ class UserImpersonation implements Feature
* *
* @param string|ImpersonationToken $token * @param string|ImpersonationToken $token
* @param int $ttl * @param int $ttl
* @return RedirectResponse
*/ */
public static function makeResponse($token, int $ttl = null): RedirectResponse public static function makeResponse($token, int $ttl = null): RedirectResponse
{ {

View file

@ -48,8 +48,7 @@ class UpdateSyncedResource extends QueueableListener
protected function updateResourceInCentralDatabaseAndGetTenants($event, $syncedAttributes) protected function updateResourceInCentralDatabaseAndGetTenants($event, $syncedAttributes)
{ {
/** @var Model|SyncMaster $centralModel */ /** @var Model|SyncMaster $centralModel */
$centralModel = $event->model->getCentralModelName() $centralModel = $event->model->getCentralModelName()::where($event->model->getGlobalIdentifierKeyName(), $event->model->getGlobalIdentifierKey())
::where($event->model->getGlobalIdentifierKeyName(), $event->model->getGlobalIdentifierKey())
->first(); ->first();
// We disable events for this call, to avoid triggering this event & listener again. // We disable events for this call, to avoid triggering this event & listener again.

View file

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Middleware; namespace Stancl\Tenancy\Middleware;
use Closure; use Closure;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode; use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException; use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
use Symfony\Component\HttpFoundation\IpUtils; use Symfony\Component\HttpFoundation\IpUtils;
use Symfony\Component\HttpKernel\Exception\HttpException;
class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode
{ {

View file

@ -29,13 +29,13 @@ class InitializeTenancyByDomain extends IdentificationMiddleware
* Handle an incoming request. * Handle an incoming request.
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
return $this->initializeTenancy( return $this->initializeTenancy(
$request, $next, $request->getHost() $request,
$next,
$request->getHost()
); );
} }
} }

View file

@ -13,8 +13,6 @@ class InitializeTenancyByDomainOrSubdomain
* Handle an incoming request. * Handle an incoming request.
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {

View file

@ -38,7 +38,9 @@ class InitializeTenancyByPath extends IdentificationMiddleware
// simply injected into some route controller action. // simply injected into some route controller action.
if ($route->parameterNames()[0] === PathTenantResolver::$tenantParameterName) { if ($route->parameterNames()[0] === PathTenantResolver::$tenantParameterName) {
return $this->initializeTenancy( return $this->initializeTenancy(
$request, $next, $route $request,
$next,
$route
); );
} else { } else {
throw new RouteIsMissingTenantParameterException; throw new RouteIsMissingTenantParameterException;

View file

@ -36,8 +36,6 @@ class InitializeTenancyByRequestData extends IdentificationMiddleware
* Handle an incoming request. * Handle an incoming request.
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {

View file

@ -28,8 +28,6 @@ class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
* Handle an incoming request. * Handle an incoming request.
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {

View file

@ -75,7 +75,6 @@ abstract class CachedTenantResolver implements TenantResolver
/** /**
* Get all the arg combinations for resolve() that can be used to find this tenant. * Get all the arg combinations for resolve() that can be used to find this tenant.
* *
* @param Tenant $tenant
* @return array[] * @return array[]
*/ */
abstract public function getArgsForTenant(Tenant $tenant): array; abstract public function getArgsForTenant(Tenant $tenant): array;

View file

@ -27,7 +27,6 @@ class Tenancy
/** /**
* Initializes the tenant. * Initializes the tenant.
* @param Tenant|int|string $tenant * @param Tenant|int|string $tenant
* @return void
*/ */
public function initialize($tenant): void public function initialize($tenant): void
{ {
@ -106,9 +105,6 @@ class Tenancy
/** /**
* Run a callback in the central context. * Run a callback in the central context.
* Atomic, safely reverts to previous context. * Atomic, safely reverts to previous context.
*
* @param callable $callback
* @return mixed
*/ */
public function central(callable $callback) public function central(callable $callback)
{ {
@ -132,7 +128,6 @@ class Tenancy
* More performant than running $tenant->run() one by one. * More performant than running $tenant->run() one by one.
* *
* @param Tenant[]|\Traversable|string[]|null $tenants * @param Tenant[]|\Traversable|string[]|null $tenants
* @param callable $callback
* @return void * @return void
*/ */
public function runForMultiple($tenants, callable $callback) public function runForMultiple($tenants, callable $callback)

View file

@ -15,8 +15,6 @@ class TenancyServiceProvider extends ServiceProvider
{ {
/** /**
* Register services. * Register services.
*
* @return void
*/ */
public function register(): void public function register(): void
{ {
@ -76,8 +74,6 @@ class TenancyServiceProvider extends ServiceProvider
/** /**
* Bootstrap services. * Bootstrap services.
*
* @return void
*/ */
public function boot(): void public function boot(): void
{ {

View file

@ -5,26 +5,26 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Tests; namespace Stancl\Tenancy\Tests;
use Illuminate\Filesystem\FilesystemAdapter; 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\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Events\TenancyEnded; use Illuminate\Support\Str;
use Stancl\Tenancy\Jobs\CreateDatabase; use ReflectionObject;
use Stancl\Tenancy\Events\TenantCreated; use ReflectionProperty;
use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\JobPipeline\JobPipeline;
use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; 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 class BootstrapperTest extends TestCase
{ {

View file

@ -19,7 +19,7 @@ class ExampleSeeder extends Seeder
{ {
DB::table('users')->insert([ DB::table('users')->insert([
'name' => Str::random(10), 'name' => Str::random(10),
'email' => Str::random(10).'@gmail.com', 'email' => Str::random(10) . '@gmail.com',
'password' => bcrypt('password'), 'password' => bcrypt('password'),
]); ]);
} }

View file

@ -20,7 +20,6 @@ use Stancl\Tenancy\Jobs\CreateDatabase;
use Stancl\Tenancy\Jobs\MigrateDatabase; use Stancl\Tenancy\Jobs\MigrateDatabase;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\QueueableListener; use Stancl\Tenancy\Listeners\QueueableListener;
use Stancl\Tenancy\Tenancy;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
class EventListenerTest extends TestCase class EventListenerTest extends TestCase

View file

@ -4,14 +4,12 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Tests; namespace Stancl\Tenancy\Tests;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\Database\Concerns\MaintenanceMode; use Stancl\Tenancy\Database\Concerns\MaintenanceMode;
use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode; use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
class MaintenanceModeTest extends TestCase class MaintenanceModeTest extends TestCase
{ {

View file

@ -4,33 +4,31 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Tests; namespace Stancl\Tenancy\Tests;
use Closure;
use Exception; use Exception;
use Illuminate\Support\Str;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Spatie\Valuestore\Valuestore; use Illuminate\Contracts\Queue\ShouldQueue;
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\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\Events\JobProcessed; use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing; use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\SerializesModels;
use PDO; 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\TenancyInitialized;
use Stancl\Tenancy\Events\TenantCreated;
use Stancl\Tenancy\Jobs\CreateDatabase;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper; use Stancl\Tenancy\Tests\Etc\Tenant;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Tests\Etc\User;
class QueueTest extends TestCase class QueueTest extends TestCase
{ {

View file

@ -589,7 +589,9 @@ class CentralUser extends Model implements SyncMaster
use ResourceSyncing, CentralConnection; use ResourceSyncing, CentralConnection;
protected $guarded = []; protected $guarded = [];
public $timestamps = false; public $timestamps = false;
public $table = 'users'; public $table = 'users';
public function tenants(): BelongsToMany public function tenants(): BelongsToMany
@ -633,7 +635,9 @@ class ResourceUser extends Model implements Syncable
use ResourceSyncing; use ResourceSyncing;
protected $table = 'users'; protected $table = 'users';
protected $guarded = []; protected $guarded = [];
public $timestamps = false; public $timestamps = false;
public function getGlobalIdentifierKey() public function getGlobalIdentifierKey()

View file

@ -329,6 +329,7 @@ class Post extends Model
use BelongsToTenant; use BelongsToTenant;
protected $guarded = []; protected $guarded = [];
public $timestamps = false; public $timestamps = false;
public function comments() public function comments()
@ -345,6 +346,7 @@ class Post extends Model
class Comment extends Model class Comment extends Model
{ {
protected $guarded = []; protected $guarded = [];
public $timestamps = false; public $timestamps = false;
public function post() public function post()
@ -368,5 +370,6 @@ class ScopedComment extends Comment
class GlobalResource extends Model class GlobalResource extends Model
{ {
protected $guarded = []; protected $guarded = [];
public $timestamps = false; public $timestamps = false;
} }

View file

@ -104,7 +104,7 @@ class TenantDatabaseManagerTest extends TestCase
['sqlite', SQLiteDatabaseManager::class], ['sqlite', SQLiteDatabaseManager::class],
['pgsql', PostgreSQLDatabaseManager::class], ['pgsql', PostgreSQLDatabaseManager::class],
['pgsql', PostgreSQLSchemaManager::class], ['pgsql', PostgreSQLSchemaManager::class],
['sqlsrv', MicrosoftSQLDatabaseManager::class] ['sqlsrv', MicrosoftSQLDatabaseManager::class],
]; ];
} }

View file

@ -172,6 +172,7 @@ class MyTenant extends Tenant
class AnotherTenant extends Model implements Contracts\Tenant class AnotherTenant extends Model implements Contracts\Tenant
{ {
protected $guarded = []; protected $guarded = [];
protected $table = 'tenants'; protected $table = 'tenants';
public function getTenantKeyName(): string public function getTenantKeyName(): string

View file

@ -274,11 +274,13 @@ class TenantUserImpersonationTest extends TestCase
class ImpersonationUser extends Authenticable class ImpersonationUser extends Authenticable
{ {
protected $guarded = []; protected $guarded = [];
protected $table = 'users'; protected $table = 'users';
} }
class AnotherImpersonationUser extends Authenticable class AnotherImpersonationUser extends Authenticable
{ {
protected $guarded = []; protected $guarded = [];
protected $table = 'users'; protected $table = 'users';
} }