1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:34:04 +00:00
This commit is contained in:
Samuel Štancl 2019-08-16 18:32:06 +02:00
commit dc96931a76
21 changed files with 75 additions and 73 deletions

View file

@ -1,4 +1,6 @@
preset: laravel preset: laravel
enabled:
- native_function_invocation
disabled: disabled:
- concat_without_spaces - concat_without_spaces
- ternary_operator_spaces - ternary_operator_spaces

View file

@ -18,7 +18,7 @@ class CacheManager extends BaseCacheManager
$names = $parameters[0]; $names = $parameters[0];
$names = (array) $names; // cache()->tags('foo') https://laravel.com/docs/5.7/cache#removing-tagged-cache-items $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); return $this->store()->tags($tags)->$method(...$parameters);

View file

@ -34,14 +34,14 @@ class Install extends Command
]); ]);
$this->info('✔️ Created config/tenancy.php'); $this->info('✔️ Created config/tenancy.php');
file_put_contents(app_path('Http/Kernel.php'), str_replace( \file_put_contents(app_path('Http/Kernel.php'), \str_replace(
'protected $middlewarePriority = [', 'protected $middlewarePriority = [',
"protected \$middlewarePriority = [\n \Stancl\Tenancy\Middleware\InitializeTenancy::class,", "protected \$middlewarePriority = [\n \Stancl\Tenancy\Middleware\InitializeTenancy::class,",
file_get_contents(app_path('Http/Kernel.php')) \file_get_contents(app_path('Http/Kernel.php'))
)); ));
$this->info('✔️ Set middleware priority'); $this->info('✔️ Set middleware priority');
file_put_contents(base_path('routes/tenant.php'), \file_put_contents(base_path('routes/tenant.php'),
"<?php "<?php
/* /*

View file

@ -40,7 +40,7 @@ class Run extends Command
$callback = function ($prefix = '') { $callback = function ($prefix = '') {
return function ($arguments, $argument) use ($prefix) { return function ($arguments, $argument) use ($prefix) {
[$key, $value] = explode('=', $argument, 2); [$key, $value] = \explode('=', $argument, 2);
$arguments[$prefix . $key] = $value; $arguments[$prefix . $key] = $value;
return $arguments; return $arguments;
@ -48,13 +48,13 @@ class Run extends Command
}; };
// Turns ['foo=bar', 'abc=xyz=zzz'] into ['foo' => 'bar', 'abc' => 'xyz=zzz'] // 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'] // 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 // Run command
$this->call($this->argument('commandname'), array_merge($arguments, $options)); $this->call($this->argument('commandname'), \array_merge($arguments, $options));
tenancy()->end(); tenancy()->end();
}); });

View file

@ -50,7 +50,7 @@ final class DatabaseManager
$databaseManagers = config('tenancy.database_managers'); $databaseManagers = config('tenancy.database_managers');
if (! array_key_exists($driver, $databaseManagers)) { if (! \array_key_exists($driver, $databaseManagers)) {
throw new \Exception("Database could not be created: no database manager for driver $driver is registered."); throw new \Exception("Database could not be created: no database manager for driver $driver is registered.");
} }
@ -76,7 +76,7 @@ final class DatabaseManager
$databaseManagers = config('tenancy.database_managers'); $databaseManagers = config('tenancy.database_managers');
if (! array_key_exists($driver, $databaseManagers)) { if (! \array_key_exists($driver, $databaseManagers)) {
throw new \Exception("Database could not be deleted: no database manager for driver $driver is registered."); throw new \Exception("Database could not be deleted: no database manager for driver $driver is registered.");
} }

View file

@ -37,7 +37,7 @@ class RedisStorageDriver implements StorageDriver
return $this->redis->hgetall("tenants:$uuid"); return $this->redis->hgetall("tenants:$uuid");
} }
return array_combine($fields, $this->redis->hmget("tenants:$uuid", $fields)); return \array_combine($fields, $this->redis->hmget("tenants:$uuid", $fields));
} }
public function getTenantIdByDomain(string $domain): ?string public function getTenantIdByDomain(string $domain): ?string
@ -48,7 +48,7 @@ class RedisStorageDriver implements StorageDriver
public function createTenant(string $domain, string $uuid): array public function createTenant(string $domain, string $uuid): array
{ {
$this->redis->hmset("domains:$domain", 'tenant_id', $uuid); $this->redis->hmset("domains:$domain", 'tenant_id', $uuid);
$this->redis->hmset("tenants:$uuid", 'uuid', json_encode($uuid), 'domain', json_encode($domain)); $this->redis->hmset("tenants:$uuid", 'uuid', \json_encode($uuid), 'domain', \json_encode($domain));
return $this->redis->hgetall("tenants:$uuid"); return $this->redis->hgetall("tenants:$uuid");
} }
@ -63,7 +63,7 @@ class RedisStorageDriver implements StorageDriver
public function deleteTenant(string $id): bool public function deleteTenant(string $id): bool
{ {
try { try {
$domain = json_decode($this->getTenantById($id)['domain']); $domain = \json_decode($this->getTenantById($id)['domain']);
} catch (\Throwable $th) { } catch (\Throwable $th) {
throw new \Exception("No tenant with UUID $id exists."); throw new \Exception("No tenant with UUID $id exists.");
} }
@ -75,7 +75,7 @@ class RedisStorageDriver implements StorageDriver
public function getAllTenants(array $uuids = []): array public function getAllTenants(array $uuids = []): array
{ {
$hashes = array_map(function ($hash) { $hashes = \array_map(function ($hash) {
return "tenants:{$hash}"; return "tenants:{$hash}";
}, $uuids); }, $uuids);
@ -91,13 +91,13 @@ class RedisStorageDriver implements StorageDriver
$all_keys = $this->redis->scan(null, 'MATCH', $redis_prefix . 'tenants:*')[1]; $all_keys = $this->redis->scan(null, 'MATCH', $redis_prefix . 'tenants:*')[1];
} }
$hashes = array_map(function ($key) use ($redis_prefix) { $hashes = \array_map(function ($key) use ($redis_prefix) {
// Left strip $redis_prefix from $key // Left strip $redis_prefix from $key
return substr($key, strlen($redis_prefix)); return \substr($key, \strlen($redis_prefix));
}, $all_keys); }, $all_keys);
} }
return array_map(function ($tenant) { return \array_map(function ($tenant) {
return $this->redis->hgetall($tenant); return $this->redis->hgetall($tenant);
}, $hashes); }, $hashes);
} }

View file

@ -54,14 +54,14 @@ class Tenant extends Model
public static function decodeData($tenant) public static function decodeData($tenant)
{ {
$tenant = $tenant instanceof self ? (array) $tenant->attributes : $tenant; $tenant = $tenant instanceof self ? (array) $tenant->attributes : $tenant;
$decoded = json_decode($tenant[$dataColumn = static::dataColumn()], true); $decoded = \json_decode($tenant[$dataColumn = static::dataColumn()], true);
foreach ($decoded as $key => $value) { foreach ($decoded as $key => $value) {
$tenant[$key] = $value; $tenant[$key] = $value;
} }
// If $tenant[$dataColumn] has been overriden by a value, don't delete the key. // If $tenant[$dataColumn] has been overriden by a value, don't delete the key.
if (! array_key_exists($dataColumn, $decoded)) { if (! \array_key_exists($dataColumn, $decoded)) {
unset($tenant[$dataColumn]); unset($tenant[$dataColumn]);
} }
@ -70,7 +70,7 @@ class Tenant extends Model
public function getFromData(string $key) public function getFromData(string $key)
{ {
$this->dataArray = $this->dataArray ?? json_decode($this->{$this->dataColumn()}, true); $this->dataArray = $this->dataArray ?? \json_decode($this->{$this->dataColumn()}, true);
return $this->dataArray[$key] ?? null; return $this->dataArray[$key] ?? null;
} }
@ -83,18 +83,18 @@ class Tenant extends Model
/** @todo In v2, this should return an associative array. */ /** @todo In v2, this should return an associative array. */
public function getMany(array $keys): array public function getMany(array $keys): array
{ {
return array_map([$this, 'get'], $keys); return \array_map([$this, 'get'], $keys);
} }
public function put(string $key, $value) public function put(string $key, $value)
{ {
if (array_key_exists($key, $this->customColumns())) { if (\array_key_exists($key, $this->customColumns())) {
$this->update([$key => $value]); $this->update([$key => $value]);
} else { } else {
$obj = json_decode($this->{$this->dataColumn()}); $obj = \json_decode($this->{$this->dataColumn()});
$obj->$key = $value; $obj->$key = $value;
$this->update([$this->dataColumn() => json_encode($obj)]); $this->update([$this->dataColumn() => \json_encode($obj)]);
} }
return $value; return $value;

View file

@ -9,7 +9,7 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
public function createDatabase(string $name): bool public function createDatabase(string $name): bool
{ {
try { try {
return fclose(fopen(database_path($name), 'w')); return \fclose(\fopen(database_path($name), 'w'));
} catch (\Throwable $th) { } catch (\Throwable $th) {
return false; return false;
} }
@ -18,7 +18,7 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
public function deleteDatabase(string $name): bool public function deleteDatabase(string $name): bool
{ {
try { try {
return unlink(database_path($name)); return \unlink(database_path($name));
} catch (\Throwable $th) { } catch (\Throwable $th) {
return false; return false;
} }

View file

@ -64,7 +64,7 @@ final class TenantManager
$tenant = $this->storage->identifyTenant($domain); $tenant = $this->storage->identifyTenant($domain);
if (! $tenant || ! array_key_exists('uuid', $tenant) || ! $tenant['uuid']) { if (! $tenant || ! \array_key_exists('uuid', $tenant) || ! $tenant['uuid']) {
throw new \Exception("Tenant could not be identified on domain {$domain}."); throw new \Exception("Tenant could not be identified on domain {$domain}.");
} }
@ -94,7 +94,7 @@ final class TenantManager
if ($data) { if ($data) {
$this->put($data, null, $tenant['uuid']); $this->put($data, null, $tenant['uuid']);
$tenant = array_merge($tenant, $data); $tenant = \array_merge($tenant, $data);
} }
$this->database->create($this->getDatabaseName($tenant)); $this->database->create($this->getDatabaseName($tenant));
@ -175,7 +175,7 @@ final class TenantManager
$uuid = $this->getIdByDomain($domain); $uuid = $this->getIdByDomain($domain);
if (is_null($uuid)) { if (\is_null($uuid)) {
throw new \Exception("Tenant with domain $domain could not be identified."); throw new \Exception("Tenant with domain $domain could not be identified.");
} }
@ -240,7 +240,7 @@ final class TenantManager
$tenants = $this->storage->getAllTenants($uuids); $tenants = $this->storage->getAllTenants($uuids);
if ($this->useJson()) { if ($this->useJson()) {
$tenants = array_map(function ($tenant_array) { $tenants = \array_map(function ($tenant_array) {
return $this->jsonDecodeArrayValues($tenant_array); return $this->jsonDecodeArrayValues($tenant_array);
}, $tenants); }, $tenants);
} }
@ -273,8 +273,8 @@ final class TenantManager
{ {
$uuid = $uuid ?: $this->tenant['uuid']; $uuid = $uuid ?: $this->tenant['uuid'];
if (array_key_exists('uuid', $this->tenant) && $uuid === $this->tenant['uuid'] && if (\array_key_exists('uuid', $this->tenant) && $uuid === $this->tenant['uuid'] &&
! is_array($key) && array_key_exists($key, $this->tenant)) { ! \is_array($key) && \array_key_exists($key, $this->tenant)) {
return $this->tenant[$key]; return $this->tenant[$key];
} }
@ -282,7 +282,7 @@ final class TenantManager
return $this->jsonDecodeArrayValues($this->storage->getMany($uuid, $key)); return $this->jsonDecodeArrayValues($this->storage->getMany($uuid, $key));
} }
return json_decode($this->storage->get($uuid, $key), true); return \json_decode($this->storage->get($uuid, $key), true);
} }
/** /**
@ -295,10 +295,10 @@ final class TenantManager
*/ */
public function put($key, $value = null, string $uuid = null) public function put($key, $value = null, string $uuid = null)
{ {
if (in_array($key, ['uuid', 'domain'], true) || ( if (\in_array($key, ['uuid', 'domain'], true) || (
is_array($key) && ( \is_array($key) && (
in_array('uuid', array_keys($key), true) || \in_array('uuid', \array_keys($key), true) ||
in_array('domain', array_keys($key), true) \in_array('domain', \array_keys($key), true)
) )
)) { )) {
throw new CannotChangeUuidOrDomainException; throw new CannotChangeUuidOrDomainException;
@ -319,7 +319,7 @@ final class TenantManager
} }
if (! \is_null($value)) { if (! \is_null($value)) {
return $target[$key] = json_decode($this->storage->put($uuid, $key, json_encode($value)), true); return $target[$key] = \json_decode($this->storage->put($uuid, $key, \json_encode($value)), true);
} }
if (! \is_array($key)) { if (! \is_array($key)) {
@ -328,7 +328,7 @@ final class TenantManager
foreach ($key as $k => $v) { foreach ($key as $k => $v) {
$target[$k] = $v; $target[$k] = $v;
$key[$k] = json_encode($v); $key[$k] = \json_encode($v);
} }
return $this->jsonDecodeArrayValues($this->storage->putMany($uuid, $key)); return $this->jsonDecodeArrayValues($this->storage->putMany($uuid, $key));
@ -349,8 +349,8 @@ final class TenantManager
protected function jsonDecodeArrayValues(array $array) protected function jsonDecodeArrayValues(array $array)
{ {
array_walk($array, function (&$value, $key) { \array_walk($array, function (&$value, $key) {
$value = json_decode($value, true); $value = \json_decode($value, true);
}); });
return $array; return $array;
@ -358,7 +358,7 @@ final class TenantManager
public function useJson() public function useJson()
{ {
if (property_exists($this->storage, 'useJson') && $this->storage->useJson === false) { if (\property_exists($this->storage, 'useJson') && $this->storage->useJson === false) {
return false; return false;
} }

View file

@ -10,7 +10,7 @@ class TenantRouteServiceProvider extends RouteServiceProvider
public function map() public function map()
{ {
if (! \in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? []) if (! \in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? [])
&& file_exists(base_path('routes/tenant.php'))) { && \file_exists(base_path('routes/tenant.php'))) {
Route::middleware(['web', 'tenancy']) Route::middleware(['web', 'tenancy'])
->namespace($this->app['config']['tenant_route_namespace'] ?? 'App\Http\Controllers') ->namespace($this->app['config']['tenant_route_namespace'] ?? 'App\Http\Controllers')
->group(base_path('routes/tenant.php')); ->group(base_path('routes/tenant.php'));

View file

@ -138,7 +138,7 @@ trait BootstrapsTenancy
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) { foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
$old['disks'][$disk] = Storage::disk($disk)->getAdapter()->getPathPrefix(); $old['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); Storage::disk($disk)->getAdapter()->setPathPrefix($root);
} else { } else {
$root = $this->app['config']["filesystems.disks.{$disk}.root"]; $root = $this->app['config']["filesystems.disks.{$disk}.root"];

View file

@ -8,7 +8,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

@ -78,7 +78,7 @@ trait TenantManagerEvents
*/ */
public function event(string $name): Collection public function event(string $name): Collection
{ {
return array_reduce($this->listeners[$name], function ($prevents, $listener) { return \array_reduce($this->listeners[$name], function ($prevents, $listener) {
return $prevents->merge($listener($this) ?? []); return $prevents->merge($listener($this) ?? []);
}, collect([])); }, collect([]));
} }

View file

@ -2,7 +2,7 @@
use Stancl\Tenancy\TenantManager; use Stancl\Tenancy\TenantManager;
if (! function_exists('tenancy')) { if (! \function_exists('tenancy')) {
function tenancy($key = null) function tenancy($key = null)
{ {
if ($key) { if ($key) {
@ -13,14 +13,14 @@ if (! function_exists('tenancy')) {
} }
} }
if (! function_exists('tenant')) { if (! \function_exists('tenant')) {
function tenant($key = null) function tenant($key = null)
{ {
return tenancy($key); return tenancy($key);
} }
} }
if (! function_exists('tenant_asset')) { if (! \function_exists('tenant_asset')) {
function tenant_asset($asset) function tenant_asset($asset)
{ {
return route('stancl.tenancy.asset', ['asset' => $asset]); return route('stancl.tenancy.asset', ['asset' => $asset]);

View file

@ -86,7 +86,7 @@ class BootstrapsTenancyTest extends TestCase
$current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix(); $current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix();
if ($override = config("tenancy.filesystem.root_override.{$disk}")) { 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 { } else {
if ($base = $old_storage_facade_roots[$disk]) { if ($base = $old_storage_facade_roots[$disk]) {
$correct_path_prefix = $base . "/$suffix/"; $correct_path_prefix = $base . "/$suffix/";

View file

@ -117,14 +117,14 @@ class CommandsTest extends TestCase
/** @test */ /** @test */
public function install_command_works() public function install_command_works()
{ {
if (! is_dir($dir = app_path('Http'))) { if (! \is_dir($dir = app_path('Http'))) {
mkdir($dir, 0777, true); \mkdir($dir, 0777, true);
} }
if (! is_dir($dir = base_path('routes'))) { if (! \is_dir($dir = base_path('routes'))) {
mkdir($dir, 0777, true); \mkdir($dir, 0777, true);
} }
file_put_contents(app_path('Http/Kernel.php'), "<?php \file_put_contents(app_path('Http/Kernel.php'), "<?php
namespace App\Http; namespace App\Http;

View file

@ -27,7 +27,7 @@ class ReidentificationTest extends TestCase
$current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix(); $current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix();
if ($override = config("tenancy.filesystem.root_override.{$disk}")) { 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 { } else {
if ($base = $originals[$disk]) { if ($base = $originals[$disk]) {
$correct_path_prefix = $base . "/$suffix/"; $correct_path_prefix = $base . "/$suffix/";

View file

@ -16,9 +16,9 @@ class TenantAssetTest extends TestCase
$this->get(tenant_asset($filename))->assertSuccessful(); $this->get(tenant_asset($filename))->assertSuccessful();
$this->assertFileExists($path); $this->assertFileExists($path);
$f = fopen($path, 'r'); $f = \fopen($path, 'r');
$content = fread($f, filesize($path)); $content = \fread($f, \filesize($path));
fclose($f); \fclose($f);
$this->assertSame('bar', $content); $this->assertSame('bar', $content);
} }

View file

@ -87,7 +87,7 @@ class TenantDatabaseManagerTest extends TestCase
config()->set('database.default', 'pgsql'); config()->set('database.default', 'pgsql');
$db_name = strtolower('testdatabase' . $this->randomString(10)); $db_name = \strtolower('testdatabase' . $this->randomString(10));
$this->assertTrue(app(DatabaseManager::class)->create($db_name, 'pgsql')); $this->assertTrue(app(DatabaseManager::class)->create($db_name, 'pgsql'));
$this->assertNotEmpty(DB::select("SELECT datname FROM pg_database WHERE datname = '$db_name'")); $this->assertNotEmpty(DB::select("SELECT datname FROM pg_database WHERE datname = '$db_name'"));
@ -104,7 +104,7 @@ class TenantDatabaseManagerTest extends TestCase
config()->set('database.default', 'pgsql'); config()->set('database.default', 'pgsql');
$db_name = strtolower('testdatabase' . $this->randomString(10)); $db_name = \strtolower('testdatabase' . $this->randomString(10));
$databaseManagers = config('tenancy.database_managers'); $databaseManagers = config('tenancy.database_managers');
$job = new QueuedTenantDatabaseCreator(app($databaseManagers['pgsql']), $db_name); $job = new QueuedTenantDatabaseCreator(app($databaseManagers['pgsql']), $db_name);

View file

@ -40,7 +40,7 @@ class TenantStorageTest extends TestCase
{ {
$keys = ['foo', 'abc']; $keys = ['foo', 'abc'];
$vals = ['bar', 'xyz']; $vals = ['bar', 'xyz'];
$data = array_combine($keys, $vals); $data = \array_combine($keys, $vals);
tenancy()->put($data); tenancy()->put($data);
dd(tenant()->get($keys)); dd(tenant()->get($keys));
@ -76,13 +76,13 @@ class TenantStorageTest extends TestCase
$keys = ['foo', 'abc']; $keys = ['foo', 'abc'];
$vals = ['bar', 'xyz']; $vals = ['bar', 'xyz'];
$data = array_combine($keys, $vals); $data = \array_combine($keys, $vals);
tenancy()->put($data, null, $uuid); tenancy()->put($data, null, $uuid);
$this->assertSame($vals, tenancy()->get($keys, $uuid)); $this->assertSame($vals, tenancy()->get($keys, $uuid));
$this->assertNotSame($vals, tenancy()->get($keys)); $this->assertNotSame($vals, tenancy()->get($keys));
$this->assertFalse(array_intersect($data, tenant()->tenant) == $data); // assert array not subset $this->assertFalse(\array_intersect($data, tenant()->tenant) == $data); // assert array not subset
} }
/** @test */ /** @test */
@ -130,15 +130,15 @@ class TenantStorageTest extends TestCase
public function data_is_stored_with_correct_data_types() public function data_is_stored_with_correct_data_types()
{ {
tenancy()->put('someBool', false); tenancy()->put('someBool', false);
$this->assertSame('boolean', gettype(tenancy()->get('someBool'))); $this->assertSame('boolean', \gettype(tenancy()->get('someBool')));
tenancy()->put('someInt', 5); tenancy()->put('someInt', 5);
$this->assertSame('integer', gettype(tenancy()->get('someInt'))); $this->assertSame('integer', \gettype(tenancy()->get('someInt')));
tenancy()->put('someDouble', 11.40); tenancy()->put('someDouble', 11.40);
$this->assertSame('double', gettype(tenancy()->get('someDouble'))); $this->assertSame('double', \gettype(tenancy()->get('someDouble')));
tenancy()->put('string', 'foo'); tenancy()->put('string', 'foo');
$this->assertSame('string', gettype(tenancy()->get('string'))); $this->assertSame('string', \gettype(tenancy()->get('string')));
} }
} }

View file

@ -24,7 +24,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
Redis::connection('cache')->flushdb(); Redis::connection('cache')->flushdb();
$this->loadMigrationsFrom([ $this->loadMigrationsFrom([
'--path' => realpath(__DIR__ . '/../assets/migrations'), '--path' => \realpath(__DIR__ . '/../assets/migrations'),
'--database' => 'central', '--database' => 'central',
]); ]);
config(['database.default' => 'sqlite']); // fix issue caused by loadMigrationsFrom config(['database.default' => 'sqlite']); // fix issue caused by loadMigrationsFrom
@ -63,11 +63,11 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
*/ */
protected function getEnvironmentSetUp($app) protected function getEnvironmentSetUp($app)
{ {
if (file_exists(__DIR__ . '/../.env')) { if (\file_exists(__DIR__ . '/../.env')) {
\Dotenv\Dotenv::create(__DIR__ . '/..')->load(); \Dotenv\Dotenv::create(__DIR__ . '/..')->load();
} }
fclose(fopen(database_path('central.sqlite'), 'w')); \fclose(\fopen(database_path('central.sqlite'), 'w'));
$app['config']->set([ $app['config']->set([
'database.redis.cache.host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'), 'database.redis.cache.host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
@ -160,7 +160,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
public function randomString(int $length = 10) public function randomString(int $length = 10)
{ {
return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length); return \substr(\str_shuffle(\str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', \ceil($length / \strlen($x)))), 1, $length);
} }
public function isContainerized() public function isContainerized()
@ -170,6 +170,6 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
public function assertArrayIsSubset($subset, $array, string $message = ''): void public function assertArrayIsSubset($subset, $array, string $message = ''): void
{ {
parent::assertTrue(array_intersect($subset, $array) == $subset, $message); parent::assertTrue(\array_intersect($subset, $array) == $subset, $message);
} }
} }