From c9903cd43c0dbb97ac67053312b641ad137e2cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Thu, 19 Sep 2019 20:32:09 +0200 Subject: [PATCH] Clean up --- src/CacheManager.php | 4 +- src/Commands/Install.php | 14 +- src/Commands/Run.php | 8 +- src/Contracts/TenancyBootstrapper.php | 2 +- src/Features/TelescopeTags.php | 2 +- .../PreventAccessFromTenantDomains.php | 4 +- .../FilesystemTenancyBootstrapper.php | 2 +- .../QueueTenancyBootstrapper.php | 4 +- src/Tenant.php | 1 - src/TenantRouteServiceProvider.php | 4 +- src/Traits/HasATenantsOption.php | 2 +- tests/CommandsTest.php | 176 +----------------- tests/Etc/defaultHttpKernel.stub | 80 ++++++++ tests/Etc/modifiedHttpKernel.stub | 83 +++++++++ tests/QueueTest.php | 2 +- tests/ReidentificationTest.php | 4 +- ...yTest.php => TenancyBootstrappersTest.php} | 7 +- tests/TenantStorageTest.php | 18 +- tests/TestCase.php | 10 +- 19 files changed, 212 insertions(+), 215 deletions(-) create mode 100644 tests/Etc/defaultHttpKernel.stub create mode 100644 tests/Etc/modifiedHttpKernel.stub rename tests/{BootstrapsTenancyTest.php => TenancyBootstrappersTest.php} (91%) diff --git a/src/CacheManager.php b/src/CacheManager.php index e361bc5c..b0e357cc 100644 --- a/src/CacheManager.php +++ b/src/CacheManager.php @@ -13,14 +13,14 @@ class CacheManager extends BaseCacheManager $tags = [config('tenancy.cache.tag_base') . tenant('id')]; if ($method === 'tags') { - if (\count($parameters) !== 1) { + if (count($parameters) !== 1) { throw new \Exception("Method tags() takes exactly 1 argument. {count($parameters)} passed."); } $names = $parameters[0]; $names = (array) $names; // cache()->tags('foo') https://laravel.com/docs/5.7/cache#removing-tagged-cache-items - return $this->store()->tags(\array_merge($tags, $names)); + return $this->store()->tags(array_merge($tags, $names)); } return $this->store()->tags($tags)->$method(...$parameters); diff --git a/src/Commands/Install.php b/src/Commands/Install.php index b25f2603..0237473b 100644 --- a/src/Commands/Install.php +++ b/src/Commands/Install.php @@ -36,21 +36,21 @@ class Install extends Command ]); $this->info('✔️ Created config/tenancy.php'); - $newKernel = \str_replace( + $newKernel = str_replace( 'protected $middlewarePriority = [', "protected \$middlewarePriority = [ \Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class, \Stancl\Tenancy\Middleware\InitializeTenancy::class,", - \file_get_contents(app_path('Http/Kernel.php')) + file_get_contents(app_path('Http/Kernel.php')) ); - $newKernel = \str_replace("'web' => [", "'web' => [ + $newKernel = str_replace("'web' => [", "'web' => [ \Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,", $newKernel); - \file_put_contents(app_path('Http/Kernel.php'), $newKernel); + file_put_contents(app_path('Http/Kernel.php'), $newKernel); $this->info('✔️ Set middleware priority'); - \file_put_contents( + file_put_contents( base_path('routes/tenant.php'), "info('✔️ Created migration.'); } - if (! \is_dir(database_path('migrations/tenant'))) { - \mkdir(database_path('migrations/tenant')); + if (! is_dir(database_path('migrations/tenant'))) { + mkdir(database_path('migrations/tenant')); $this->info('✔️ Created database/migrations/tenant folder.'); } diff --git a/src/Commands/Run.php b/src/Commands/Run.php index 87616f48..e6fc012f 100644 --- a/src/Commands/Run.php +++ b/src/Commands/Run.php @@ -39,7 +39,7 @@ class Run extends Command $callback = function ($prefix = '') { return function ($arguments, $argument) use ($prefix) { - [$key, $value] = \explode('=', $argument, 2); + [$key, $value] = explode('=', $argument, 2); $arguments[$prefix . $key] = $value; return $arguments; @@ -47,13 +47,13 @@ class Run extends Command }; // Turns ['foo=bar', 'abc=xyz=zzz'] into ['foo' => 'bar', 'abc' => 'xyz=zzz'] - $arguments = \array_reduce($this->option('argument'), $callback(), []); + $arguments = array_reduce($this->option('argument'), $callback(), []); // Turns ['foo=bar', 'abc=xyz=zzz'] into ['--foo' => 'bar', '--abc' => 'xyz=zzz'] - $options = \array_reduce($this->option('option'), $callback('--'), []); + $options = array_reduce($this->option('option'), $callback('--'), []); // Run command - $this->call($this->argument('commandname'), \array_merge($arguments, $options)); + $this->call($this->argument('commandname'), array_merge($arguments, $options)); tenancy()->endTenancy(); }); diff --git a/src/Contracts/TenancyBootstrapper.php b/src/Contracts/TenancyBootstrapper.php index 4dfb9536..5d1e2dcf 100644 --- a/src/Contracts/TenancyBootstrapper.php +++ b/src/Contracts/TenancyBootstrapper.php @@ -8,7 +8,7 @@ use Stancl\Tenancy\Tenant; interface TenancyBootstrapper { - public function start(Tenant $tenant); // todo2 TenantManager instead of Tenant + public function start(Tenant $tenant); public function end(); } diff --git a/src/Features/TelescopeTags.php b/src/Features/TelescopeTags.php index 19a1131a..bc7235c2 100644 --- a/src/Features/TelescopeTags.php +++ b/src/Features/TelescopeTags.php @@ -26,7 +26,7 @@ class TelescopeTags implements Feature if (in_array('tenancy', optional(request()->route())->middleware() ?? [])) { $tags = array_merge($tags, [ 'tenant:' . tenant('id'), - // todo2 domain? + // todo3 domain? ]); } diff --git a/src/Middleware/PreventAccessFromTenantDomains.php b/src/Middleware/PreventAccessFromTenantDomains.php index 082a613f..7aa022a4 100644 --- a/src/Middleware/PreventAccessFromTenantDomains.php +++ b/src/Middleware/PreventAccessFromTenantDomains.php @@ -19,8 +19,8 @@ class PreventAccessFromTenantDomains { // If the domain is not in exempt domains, it's a tenant domain. // Tenant domains can't have routes without tenancy middleware. - if (! \in_array(request()->getHost(), config('tenancy.exempt_domains')) && - ! \in_array('tenancy', request()->route()->middleware())) { + if (! in_array(request()->getHost(), config('tenancy.exempt_domains')) && + ! in_array('tenancy', request()->route()->middleware())) { abort(404); } diff --git a/src/TenancyBootstrappers/FilesystemTenancyBootstrapper.php b/src/TenancyBootstrappers/FilesystemTenancyBootstrapper.php index ec9c17e2..fae8d144 100644 --- a/src/TenancyBootstrappers/FilesystemTenancyBootstrapper.php +++ b/src/TenancyBootstrappers/FilesystemTenancyBootstrapper.php @@ -39,7 +39,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) { $this->originalPaths['disks'][$disk] = Storage::disk($disk)->getAdapter()->getPathPrefix(); - if ($root = \str_replace('%storage_path%', storage_path(), $this->app['config']["tenancy.filesystem.root_override.{$disk}"])) { + if ($root = str_replace('%storage_path%', storage_path(), $this->app['config']["tenancy.filesystem.root_override.{$disk}"])) { Storage::disk($disk)->getAdapter()->setPathPrefix($root); } else { $root = $this->app['config']["filesystems.disks.{$disk}.root"]; diff --git a/src/TenancyBootstrappers/QueueTenancyBootstrapper.php b/src/TenancyBootstrappers/QueueTenancyBootstrapper.php index 418ed7e5..638aa88e 100644 --- a/src/TenancyBootstrappers/QueueTenancyBootstrapper.php +++ b/src/TenancyBootstrappers/QueueTenancyBootstrapper.php @@ -22,7 +22,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper $this->app['queue']->createPayloadUsing([$this, 'createPayload']); $this->app['events']->listen(\Illuminate\Queue\Events\JobProcessing::class, function ($event) { - if (\array_key_exists('tenant_id', $event->job->payload())) { + if (array_key_exists('tenant_id', $event->job->payload())) { tenancy()->initById($event->job->payload()['tenant_id']); } }); @@ -50,7 +50,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper 'tenant_id' => $id, 'tags' => [ "tenant:$id", - // todo2 domain + // todo3 domain ], ]; } diff --git a/src/Tenant.php b/src/Tenant.php index f5595dce..2b758ed5 100644 --- a/src/Tenant.php +++ b/src/Tenant.php @@ -11,7 +11,6 @@ use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator; use Stancl\Tenancy\Exceptions\TenantStorageException; // todo2 write tests for updating the tenant -// todo2 addDomain(), removeDomain() /** * @internal Class is subject to breaking changes in minor and patch versions. diff --git a/src/TenantRouteServiceProvider.php b/src/TenantRouteServiceProvider.php index 84cfdefd..e0ab3335 100644 --- a/src/TenantRouteServiceProvider.php +++ b/src/TenantRouteServiceProvider.php @@ -11,8 +11,8 @@ class TenantRouteServiceProvider extends RouteServiceProvider { public function map() { - if (! \in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? []) - && \file_exists(base_path('routes/tenant.php'))) { + if (! in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? []) + && file_exists(base_path('routes/tenant.php'))) { Route::middleware(['web', 'tenancy']) ->namespace($this->app['config']['tenant_route_namespace'] ?? 'App\Http\Controllers') ->group(base_path('routes/tenant.php')); diff --git a/src/Traits/HasATenantsOption.php b/src/Traits/HasATenantsOption.php index 26680d03..4d6b247d 100644 --- a/src/Traits/HasATenantsOption.php +++ b/src/Traits/HasATenantsOption.php @@ -10,7 +10,7 @@ trait HasATenantsOption { protected function getOptions() { - return \array_merge([ + return array_merge([ ['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null], ], parent::getOptions()); } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 49055b16..cc737382 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -122,95 +122,14 @@ class CommandsTest extends TestCase /** @test */ public function install_command_works() { - if (! \is_dir($dir = app_path('Http'))) { - \mkdir($dir, 0777, true); + if (! is_dir($dir = app_path('Http'))) { + mkdir($dir, 0777, true); } - if (! \is_dir($dir = base_path('routes'))) { - \mkdir($dir, 0777, true); + if (! is_dir($dir = base_path('routes'))) { + mkdir($dir, 0777, true); } - // todo2 move this to a file - \file_put_contents(app_path('Http/Kernel.php'), " [ - \App\Http\Middleware\EncryptCookies::class, - \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, - \Illuminate\Session\Middleware\StartSession::class, - // \Illuminate\Session\Middleware\AuthenticateSession::class, - \Illuminate\View\Middleware\ShareErrorsFromSession::class, - \App\Http\Middleware\VerifyCsrfToken::class, - \Illuminate\Routing\Middleware\SubstituteBindings::class, - ], - - 'api' => [ - 'throttle:60,1', - 'bindings', - ], - ]; - - /** - * The application's route middleware. - * - * These middleware may be assigned to groups or used individually. - * - * @var array - */ - protected \$routeMiddleware = [ - 'auth' => \App\Http\Middleware\Authenticate::class, - 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, - 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, - 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, - 'can' => \Illuminate\Auth\Middleware\Authorize::class, - 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, - 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, - 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, - ]; - - /** - * The priority-sorted list of middleware. - * - * This forces non-global middleware to always be in the given order. - * - * @var array - */ - protected \$middlewarePriority = [ - \Illuminate\Session\Middleware\StartSession::class, - \Illuminate\View\Middleware\ShareErrorsFromSession::class, - \App\Http\Middleware\Authenticate::class, - \Illuminate\Session\Middleware\AuthenticateSession::class, - \Illuminate\Routing\Middleware\SubstituteBindings::class, - \Illuminate\Auth\Middleware\Authorize::class, - ]; -} -"); + file_put_contents(app_path('Http/Kernel.php'), file_get_contents(__DIR__ . '/Etc/defaultHttpKernel.stub')); $this->artisan('tenancy:install') ->expectsQuestion('Do you want to publish the default database migration?', 'yes'); @@ -218,89 +137,6 @@ class Kernel extends HttpKernel $this->assertFileExists(base_path('config/tenancy.php')); $this->assertFileExists(database_path('migrations/2019_08_08_000000_create_tenants_table.php')); $this->assertDirectoryExists(database_path('migrations/tenant')); - $this->assertSame(" [ - \Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class, - \App\Http\Middleware\EncryptCookies::class, - \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, - \Illuminate\Session\Middleware\StartSession::class, - // \Illuminate\Session\Middleware\AuthenticateSession::class, - \Illuminate\View\Middleware\ShareErrorsFromSession::class, - \App\Http\Middleware\VerifyCsrfToken::class, - \Illuminate\Routing\Middleware\SubstituteBindings::class, - ], - - 'api' => [ - 'throttle:60,1', - 'bindings', - ], - ]; - - /** - * The application's route middleware. - * - * These middleware may be assigned to groups or used individually. - * - * @var array - */ - protected \$routeMiddleware = [ - 'auth' => \App\Http\Middleware\Authenticate::class, - 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, - 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, - 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, - 'can' => \Illuminate\Auth\Middleware\Authorize::class, - 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, - 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, - 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, - ]; - - /** - * The priority-sorted list of middleware. - * - * This forces non-global middleware to always be in the given order. - * - * @var array - */ - protected \$middlewarePriority = [ - \Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class, - \Stancl\Tenancy\Middleware\InitializeTenancy::class, - \Illuminate\Session\Middleware\StartSession::class, - \Illuminate\View\Middleware\ShareErrorsFromSession::class, - \App\Http\Middleware\Authenticate::class, - \Illuminate\Session\Middleware\AuthenticateSession::class, - \Illuminate\Routing\Middleware\SubstituteBindings::class, - \Illuminate\Auth\Middleware\Authorize::class, - ]; -} -", \file_get_contents(app_path('Http/Kernel.php'))); + $this->assertSame(file_get_contents(__DIR__ . '/Etc/modifiedHttpKernel.stub'), file_get_contents(app_path('Http/Kernel.php'))); } } diff --git a/tests/Etc/defaultHttpKernel.stub b/tests/Etc/defaultHttpKernel.stub new file mode 100644 index 00000000..0c83951c --- /dev/null +++ b/tests/Etc/defaultHttpKernel.stub @@ -0,0 +1,80 @@ + [ + \App\Http\Middleware\EncryptCookies::class, + \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, + \Illuminate\Session\Middleware\StartSession::class, + // \Illuminate\Session\Middleware\AuthenticateSession::class, + \Illuminate\View\Middleware\ShareErrorsFromSession::class, + \App\Http\Middleware\VerifyCsrfToken::class, + \Illuminate\Routing\Middleware\SubstituteBindings::class, + ], + + 'api' => [ + 'throttle:60,1', + 'bindings', + ], + ]; + + /** + * The application's route middleware. + * + * These middleware may be assigned to groups or used individually. + * + * @var array + */ + protected $routeMiddleware = [ + 'auth' => \App\Http\Middleware\Authenticate::class, + 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, + 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, + 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, + 'can' => \Illuminate\Auth\Middleware\Authorize::class, + 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + ]; + + /** + * The priority-sorted list of middleware. + * + * This forces non-global middleware to always be in the given order. + * + * @var array + */ + protected $middlewarePriority = [ + \Illuminate\Session\Middleware\StartSession::class, + \Illuminate\View\Middleware\ShareErrorsFromSession::class, + \App\Http\Middleware\Authenticate::class, + \Illuminate\Session\Middleware\AuthenticateSession::class, + \Illuminate\Routing\Middleware\SubstituteBindings::class, + \Illuminate\Auth\Middleware\Authorize::class, + ]; +} \ No newline at end of file diff --git a/tests/Etc/modifiedHttpKernel.stub b/tests/Etc/modifiedHttpKernel.stub new file mode 100644 index 00000000..86cf535c --- /dev/null +++ b/tests/Etc/modifiedHttpKernel.stub @@ -0,0 +1,83 @@ + [ + \Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class, + \App\Http\Middleware\EncryptCookies::class, + \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, + \Illuminate\Session\Middleware\StartSession::class, + // \Illuminate\Session\Middleware\AuthenticateSession::class, + \Illuminate\View\Middleware\ShareErrorsFromSession::class, + \App\Http\Middleware\VerifyCsrfToken::class, + \Illuminate\Routing\Middleware\SubstituteBindings::class, + ], + + 'api' => [ + 'throttle:60,1', + 'bindings', + ], + ]; + + /** + * The application's route middleware. + * + * These middleware may be assigned to groups or used individually. + * + * @var array + */ + protected $routeMiddleware = [ + 'auth' => \App\Http\Middleware\Authenticate::class, + 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, + 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, + 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, + 'can' => \Illuminate\Auth\Middleware\Authorize::class, + 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + ]; + + /** + * The priority-sorted list of middleware. + * + * This forces non-global middleware to always be in the given order. + * + * @var array + */ + protected $middlewarePriority = [ + \Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class, + \Stancl\Tenancy\Middleware\InitializeTenancy::class, + \Illuminate\Session\Middleware\StartSession::class, + \Illuminate\View\Middleware\ShareErrorsFromSession::class, + \App\Http\Middleware\Authenticate::class, + \Illuminate\Session\Middleware\AuthenticateSession::class, + \Illuminate\Routing\Middleware\SubstituteBindings::class, + \Illuminate\Auth\Middleware\Authorize::class, + ]; +} \ No newline at end of file diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 1af5abc9..036349b2 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -56,6 +56,6 @@ class TestJob implements ShouldQueue */ public function handle() { - logger(\json_encode(\DB::table('users')->get())); + logger(json_encode(DB::table('users')->get())); } } diff --git a/tests/ReidentificationTest.php b/tests/ReidentificationTest.php index 74c21492..c5bbacc5 100644 --- a/tests/ReidentificationTest.php +++ b/tests/ReidentificationTest.php @@ -28,10 +28,10 @@ class ReidentificationTest extends TestCase foreach (config('tenancy.filesystem.disks') as $disk) { $suffix = config('tenancy.filesystem.suffix_base') . tenant('id'); - $current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix(); + $current_path_prefix = Storage::disk($disk)->getAdapter()->getPathPrefix(); if ($override = config("tenancy.filesystem.root_override.{$disk}")) { - $correct_path_prefix = \str_replace('%storage_path%', storage_path(), $override); + $correct_path_prefix = str_replace('%storage_path%', storage_path(), $override); } else { if ($base = $originals[$disk]) { $correct_path_prefix = $base . "/$suffix/"; diff --git a/tests/BootstrapsTenancyTest.php b/tests/TenancyBootstrappersTest.php similarity index 91% rename from tests/BootstrapsTenancyTest.php rename to tests/TenancyBootstrappersTest.php index 310784cf..720fc9ad 100644 --- a/tests/BootstrapsTenancyTest.php +++ b/tests/TenancyBootstrappersTest.php @@ -6,8 +6,7 @@ namespace Stancl\Tenancy\Tests; use Illuminate\Support\Facades\Redis; -// todo2 rename -class BootstrapsTenancyTest extends TestCase +class TenancyBootstrappersTest extends TestCase { public $autoInitTenancy = false; @@ -53,10 +52,10 @@ class BootstrapsTenancyTest extends TestCase foreach (config('tenancy.filesystem.disks') as $disk) { $suffix = config('tenancy.filesystem.suffix_base') . tenant('id'); - $current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix(); + $current_path_prefix = Storage::disk($disk)->getAdapter()->getPathPrefix(); if ($override = config("tenancy.filesystem.root_override.{$disk}")) { - $correct_path_prefix = \str_replace('%storage_path%', storage_path(), $override); + $correct_path_prefix = str_replace('%storage_path%', storage_path(), $override); } else { if ($base = $old_storage_facade_roots[$disk]) { $correct_path_prefix = $base . "/$suffix/"; diff --git a/tests/TenantStorageTest.php b/tests/TenantStorageTest.php index 91c97dd3..6959ce55 100644 --- a/tests/TenantStorageTest.php +++ b/tests/TenantStorageTest.php @@ -95,20 +95,20 @@ class TenantStorageTest extends TestCase public function data_is_stored_with_correct_data_types() { tenant()->put('someBool', false); - $this->assertSame('boolean', \gettype(tenant()->get('someBool'))); - $this->assertSame('boolean', \gettype(tenant()->get(['someBool'])['someBool'])); + $this->assertSame('boolean', gettype(tenant()->get('someBool'))); + $this->assertSame('boolean', gettype(tenant()->get(['someBool'])['someBool'])); tenant()->put('someInt', 5); - $this->assertSame('integer', \gettype(tenant()->get('someInt'))); - $this->assertSame('integer', \gettype(tenant()->get(['someInt'])['someInt'])); + $this->assertSame('integer', gettype(tenant()->get('someInt'))); + $this->assertSame('integer', gettype(tenant()->get(['someInt'])['someInt'])); tenant()->put('someDouble', 11.40); - $this->assertSame('double', \gettype(tenant()->get('someDouble'))); - $this->assertSame('double', \gettype(tenant()->get(['someDouble'])['someDouble'])); + $this->assertSame('double', gettype(tenant()->get('someDouble'))); + $this->assertSame('double', gettype(tenant()->get(['someDouble'])['someDouble'])); tenant()->put('string', 'foo'); - $this->assertSame('string', \gettype(tenant()->get('string'))); - $this->assertSame('string', \gettype(tenant()->get(['string'])['string'])); + $this->assertSame('string', gettype(tenant()->get('string'))); + $this->assertSame('string', gettype(tenant()->get(['string'])['string'])); } /** @test */ @@ -159,6 +159,6 @@ class TenantStorageTest extends TestCase tenant()->put(['foo' => 'bar', 'abc' => 'xyz']); $this->assertSame(['bar', 'xyz'], tenant()->get(['foo', 'abc'])); - $this->assertSame('bar', \DB::connection('central')->table('tenants')->where('id', tenant('id'))->first()->foo); + $this->assertSame('bar', DB::connection('central')->table('tenants')->where('id', tenant('id'))->first()->foo); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 500d0461..56342ae3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -27,7 +27,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase Redis::connection('cache')->flushdb(); $this->loadMigrationsFrom([ - '--path' => \realpath(__DIR__ . '/../assets/migrations'), + '--path' => realpath(__DIR__ . '/../assets/migrations'), '--database' => 'central', ]); config(['database.default' => 'sqlite']); // fix issue caused by loadMigrationsFrom @@ -59,11 +59,11 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase */ protected function getEnvironmentSetUp($app) { - if (\file_exists(__DIR__ . '/../.env')) { + if (file_exists(__DIR__ . '/../.env')) { \Dotenv\Dotenv::create(__DIR__ . '/..')->load(); } - \fclose(\fopen(database_path('central.sqlite'), 'w')); + fclose(fopen(database_path('central.sqlite'), 'w')); $app['config']->set([ 'database.redis.cache.host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'), @@ -152,7 +152,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase public function randomString(int $length = 10) { - return \substr(\str_shuffle(\str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', (int) (\ceil($length / \strlen($x))))), 1, $length); + return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', (int) (ceil($length / strlen($x))))), 1, $length); } public function isContainerized() @@ -162,6 +162,6 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase public function assertArrayIsSubset($subset, $array, string $message = ''): void { - parent::assertTrue(\array_intersect($subset, $array) == $subset, $message); + parent::assertTrue(array_intersect($subset, $array) == $subset, $message); } }