mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:54:03 +00:00
uuid -> id (references in code)
This commit is contained in:
parent
a7bb709bd4
commit
79f912384b
17 changed files with 46 additions and 45 deletions
|
|
@ -37,7 +37,7 @@ return [
|
||||||
],
|
],
|
||||||
'filesystem' => [ // https://stancl-tenancy.netlify.com/docs/filesystem-tenancy/
|
'filesystem' => [ // https://stancl-tenancy.netlify.com/docs/filesystem-tenancy/
|
||||||
'suffix_base' => 'tenant',
|
'suffix_base' => 'tenant',
|
||||||
// Disks which should be suffixed with the suffix_base + tenant UUID.
|
// Disks which should be suffixed with the suffix_base + tenant id.
|
||||||
'disks' => [
|
'disks' => [
|
||||||
'local',
|
'local',
|
||||||
'public',
|
'public',
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class CacheManager extends BaseCacheManager
|
||||||
{
|
{
|
||||||
public function __call($method, $parameters)
|
public function __call($method, $parameters)
|
||||||
{
|
{
|
||||||
$tags = [config('tenancy.cache.tag_base') . tenant('uuid')];
|
$tags = [config('tenancy.cache.tag_base') . tenant('id')];
|
||||||
|
|
||||||
if ($method === 'tags') {
|
if ($method === 'tags') {
|
||||||
if (\count($parameters) !== 1) {
|
if (\count($parameters) !== 1) {
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class Install extends Command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return 'This is your multi-tenant application. The uuid of the current tenant is ' . tenant('uuid');
|
return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id');
|
||||||
});
|
});
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class Migrate extends MigrateCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})");
|
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
|
||||||
|
|
||||||
// See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection.
|
// See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection.
|
||||||
// Database connections are cached by Illuminate\Database\ConnectionResolver.
|
// Database connections are cached by Illuminate\Database\ConnectionResolver.
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class Rollback extends RollbackCommand
|
||||||
$this->input->setOption('database', 'tenant');
|
$this->input->setOption('database', 'tenant');
|
||||||
|
|
||||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})");
|
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
|
||||||
$this->database->connectToTenant($tenant);
|
$this->database->connectToTenant($tenant);
|
||||||
|
|
||||||
// Migrate
|
// Migrate
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class Run extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})");
|
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
|
||||||
tenancy()->init($tenant['domain']);
|
tenancy()->init($tenant['domain']);
|
||||||
|
|
||||||
$callback = function ($prefix = '') {
|
$callback = function ($prefix = '') {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class Seed extends SeedCommand
|
||||||
$this->input->setOption('database', 'tenant');
|
$this->input->setOption('database', 'tenant');
|
||||||
|
|
||||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})");
|
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
|
||||||
$this->database->connectToTenant($tenant);
|
$this->database->connectToTenant($tenant);
|
||||||
|
|
||||||
// Seed
|
// Seed
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class TenantList extends Command
|
||||||
{
|
{
|
||||||
$this->info('Listing all tenants.');
|
$this->info('Listing all tenants.');
|
||||||
tenancy()->all()->each(function ($tenant) {
|
tenancy()->all()->each(function ($tenant) {
|
||||||
$this->line("[Tenant] uuid: {$tenant['uuid']} @ {$tenant['domain']}");
|
$this->line("[Tenant] id: {$tenant['id']} @ {$tenant['domain']}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,12 +44,12 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
[$uuid, $domain] = tenant()->get(['uuid', 'domain']);
|
[$id, $domain] = tenant()->get(['id', 'domain']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'tenant_id' => $uuid,
|
'tenant_id' => $id,
|
||||||
'tags' => [
|
'tags' => [
|
||||||
"tenant:$uuid",
|
"tenant:$id",
|
||||||
"domain:$domain",
|
"domain:$domain",
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Tests;
|
namespace Stancl\Tenancy\Tests;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
|
|
||||||
|
// todo rename
|
||||||
class BootstrapsTenancyTest extends TestCase
|
class BootstrapsTenancyTest extends TestCase
|
||||||
{
|
{
|
||||||
public $autoInitTenancy = false;
|
public $autoInitTenancy = false;
|
||||||
|
|
@ -31,7 +31,7 @@ class BootstrapsTenancyTest extends TestCase
|
||||||
|
|
||||||
$this->initTenancy();
|
$this->initTenancy();
|
||||||
foreach (config('tenancy.redis.prefixed_connections', ['default']) as $connection) {
|
foreach (config('tenancy.redis.prefixed_connections', ['default']) as $connection) {
|
||||||
$prefix = config('tenancy.redis.prefix_base') . tenant('uuid');
|
$prefix = config('tenancy.redis.prefix_base') . tenant('id');
|
||||||
$client = Redis::connection($connection)->client();
|
$client = Redis::connection($connection)->client();
|
||||||
$this->assertEquals($prefix, $client->getOption($client::OPT_PREFIX));
|
$this->assertEquals($prefix, $client->getOption($client::OPT_PREFIX));
|
||||||
}
|
}
|
||||||
|
|
@ -49,10 +49,10 @@ class BootstrapsTenancyTest extends TestCase
|
||||||
$this->initTenancy();
|
$this->initTenancy();
|
||||||
|
|
||||||
$new_storage_path = storage_path();
|
$new_storage_path = storage_path();
|
||||||
$this->assertEquals($old_storage_path . '/' . config('tenancy.filesystem.suffix_base') . tenant('uuid'), $new_storage_path);
|
$this->assertEquals($old_storage_path . '/' . config('tenancy.filesystem.suffix_base') . tenant('id'), $new_storage_path);
|
||||||
|
|
||||||
foreach (config('tenancy.filesystem.disks') as $disk) {
|
foreach (config('tenancy.filesystem.disks') as $disk) {
|
||||||
$suffix = config('tenancy.filesystem.suffix_base') . tenant('uuid');
|
$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}")) {
|
if ($override = config("tenancy.filesystem.root_override.{$disk}")) {
|
||||||
|
|
@ -75,7 +75,7 @@ class BootstrapsTenancyTest extends TestCase
|
||||||
$this->assertSame(['foo'], cache()->tags('foo')->getTags()->getNames());
|
$this->assertSame(['foo'], cache()->tags('foo')->getTags()->getNames());
|
||||||
$this->initTenancy();
|
$this->initTenancy();
|
||||||
|
|
||||||
$expected = [config('tenancy.cache.tag_base') . tenant('uuid'), 'foo', 'bar'];
|
$expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo', 'bar'];
|
||||||
$this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames());
|
$this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,20 @@ class CacheManagerTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function default_tag_is_automatically_applied()
|
public function default_tag_is_automatically_applied()
|
||||||
{
|
{
|
||||||
$this->assertArrayIsSubset([config('tenancy.cache.tag_base') . tenant('uuid')], cache()->tags('foo')->getTags()->getNames());
|
$this->assertArrayIsSubset([config('tenancy.cache.tag_base') . tenant('id')], cache()->tags('foo')->getTags()->getNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function tags_are_merged_when_array_is_passed()
|
public function tags_are_merged_when_array_is_passed()
|
||||||
{
|
{
|
||||||
$expected = [config('tenancy.cache.tag_base') . tenant('uuid'), 'foo', 'bar'];
|
$expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo', 'bar'];
|
||||||
$this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames());
|
$this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function tags_are_merged_when_string_is_passed()
|
public function tags_are_merged_when_string_is_passed()
|
||||||
{
|
{
|
||||||
$expected = [config('tenancy.cache.tag_base') . tenant('uuid'), 'foo'];
|
$expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo'];
|
||||||
$this->assertEquals($expected, cache()->tags('foo')->getTags()->getNames());
|
$this->assertEquals($expected, cache()->tags('foo')->getTags()->getNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class CommandsTest extends TestCase
|
||||||
{
|
{
|
||||||
$tenant = tenant()->create('test.localhost');
|
$tenant = tenant()->create('test.localhost');
|
||||||
Artisan::call('tenants:migrate', [
|
Artisan::call('tenants:migrate', [
|
||||||
'--tenants' => [$tenant['uuid']],
|
'--tenants' => [$tenant['id']],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertFalse(Schema::hasTable('users'));
|
$this->assertFalse(Schema::hasTable('users'));
|
||||||
|
|
@ -106,11 +106,11 @@ class CommandsTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function run_commands_works()
|
public function run_commands_works()
|
||||||
{
|
{
|
||||||
$uuid = tenant()->create('run.localhost')['uuid'];
|
$id = tenant()->create('run.localhost')['id'];
|
||||||
|
|
||||||
Artisan::call('tenants:migrate', ['--tenants' => $uuid]);
|
Artisan::call('tenants:migrate', ['--tenants' => $id]);
|
||||||
|
|
||||||
$this->artisan("tenants:run foo --tenants=$uuid --argument='a=foo' --option='b=bar' --option='c=xyz'")
|
$this->artisan("tenants:run foo --tenants=$id --argument='a=foo' --option='b=bar' --option='c=xyz'")
|
||||||
->expectsOutput("User's name is Test command")
|
->expectsOutput("User's name is Test command")
|
||||||
->expectsOutput('foo')
|
->expectsOutput('foo')
|
||||||
->expectsOutput('xyz');
|
->expectsOutput('xyz');
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class DataSeparationTest extends TestCase
|
||||||
$tenant1 = tenancy()->create('tenant1.localhost');
|
$tenant1 = tenancy()->create('tenant1.localhost');
|
||||||
$tenant2 = tenancy()->create('tenant2.localhost');
|
$tenant2 = tenancy()->create('tenant2.localhost');
|
||||||
\Artisan::call('tenants:migrate', [
|
\Artisan::call('tenants:migrate', [
|
||||||
'--tenants' => [$tenant1['uuid'], $tenant2['uuid']],
|
'--tenants' => [$tenant1['id'], $tenant2['id']],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
tenancy()->init('tenant1.localhost');
|
tenancy()->init('tenant1.localhost');
|
||||||
|
|
@ -54,7 +54,7 @@ class DataSeparationTest extends TestCase
|
||||||
|
|
||||||
$tenant3 = tenancy()->create('tenant3.localhost');
|
$tenant3 = tenancy()->create('tenant3.localhost');
|
||||||
\Artisan::call('tenants:migrate', [
|
\Artisan::call('tenants:migrate', [
|
||||||
'--tenants' => [$tenant1['uuid'], $tenant3['uuid']],
|
'--tenants' => [$tenant1['id'], $tenant3['id']],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
tenancy()->init('tenant3.localhost');
|
tenancy()->init('tenant3.localhost');
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class QueueTest extends TestCase
|
||||||
dispatch(new TestJob());
|
dispatch(new TestJob());
|
||||||
|
|
||||||
Event::assertDispatched(JobProcessing::class, function ($event) {
|
Event::assertDispatched(JobProcessing::class, function ($event) {
|
||||||
return $event->job->payload()['tenant_uuid'] === tenant('uuid');
|
return $event->job->payload()['tenant_id'] === tenant('id');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class ReidentificationTest extends TestCase
|
||||||
tenancy()->init('second.localhost');
|
tenancy()->init('second.localhost');
|
||||||
|
|
||||||
foreach (config('tenancy.filesystem.disks') as $disk) {
|
foreach (config('tenancy.filesystem.disks') as $disk) {
|
||||||
$suffix = config('tenancy.filesystem.suffix_base') . tenant('uuid');
|
$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}")) {
|
if ($override = config("tenancy.filesystem.root_override.{$disk}")) {
|
||||||
|
|
@ -51,7 +51,7 @@ class ReidentificationTest extends TestCase
|
||||||
tenant()->create('second.localhost');
|
tenant()->create('second.localhost');
|
||||||
tenancy()->init('second.localhost');
|
tenancy()->init('second.localhost');
|
||||||
|
|
||||||
$suffix = config('tenancy.filesystem.suffix_base') . tenant('uuid');
|
$suffix = config('tenancy.filesystem.suffix_base') . tenant('id');
|
||||||
$this->assertSame($original . "/$suffix", storage_path());
|
$this->assertSame($original . "/$suffix", storage_path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class TenantManagerTest extends TestCase
|
||||||
tenant()->create('foo.localhost');
|
tenant()->create('foo.localhost');
|
||||||
tenancy()->init('foo.localhost');
|
tenancy()->init('foo.localhost');
|
||||||
|
|
||||||
$this->assertSame(tenant('uuid'), tenant()('uuid'));
|
$this->assertSame(tenant('id'), tenant()('id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -38,7 +38,7 @@ class TenantManagerTest extends TestCase
|
||||||
|
|
||||||
$this->assertNotSame($tenant, tenancy()->tenant);
|
$this->assertNotSame($tenant, tenancy()->tenant);
|
||||||
|
|
||||||
tenancy()->initById($tenant['uuid']);
|
tenancy()->initById($tenant['id']);
|
||||||
|
|
||||||
$this->assertSame($tenant, tenancy()->tenant);
|
$this->assertSame($tenant, tenancy()->tenant);
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +64,7 @@ class TenantManagerTest extends TestCase
|
||||||
tenant()->create('dev.localhost');
|
tenant()->create('dev.localhost');
|
||||||
tenancy()->init('dev.localhost');
|
tenancy()->init('dev.localhost');
|
||||||
|
|
||||||
$this->assertSame(tenant()->tenant, tenant()->find(tenant('uuid')));
|
$this->assertSame(tenant()->tenant, tenant()->find(tenant('id')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -72,7 +72,7 @@ class TenantManagerTest extends TestCase
|
||||||
{
|
{
|
||||||
$tenant = tenant()->create('foo.localhost');
|
$tenant = tenant()->create('foo.localhost');
|
||||||
|
|
||||||
$this->assertSame($tenant, tenancy()->getTenantById($tenant['uuid']));
|
$this->assertSame($tenant, tenancy()->getTenantById($tenant['id']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -87,9 +87,9 @@ class TenantManagerTest extends TestCase
|
||||||
public function initById_returns_the_tenant()
|
public function initById_returns_the_tenant()
|
||||||
{
|
{
|
||||||
$tenant = tenant()->create('foo.localhost');
|
$tenant = tenant()->create('foo.localhost');
|
||||||
$uuid = $tenant['uuid'];
|
$id = $tenant['id'];
|
||||||
|
|
||||||
$this->assertSame($tenant, tenancy()->initById($uuid));
|
$this->assertSame($tenant, tenancy()->initById($id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -185,7 +185,7 @@ class TenantManagerTest extends TestCase
|
||||||
public function tenant_can_be_deleted()
|
public function tenant_can_be_deleted()
|
||||||
{
|
{
|
||||||
$tenant = tenant()->create('foo.localhost');
|
$tenant = tenant()->create('foo.localhost');
|
||||||
tenant()->delete($tenant['uuid']);
|
tenant()->delete($tenant['id']);
|
||||||
$this->assertSame([], tenancy()->all()->toArray());
|
$this->assertSame([], tenancy()->all()->toArray());
|
||||||
|
|
||||||
$tenant = tenant()->create('foo.localhost');
|
$tenant = tenant()->create('foo.localhost');
|
||||||
|
|
@ -207,7 +207,7 @@ class TenantManagerTest extends TestCase
|
||||||
$tenant = tenant()->create('foo.localhost', $data);
|
$tenant = tenant()->create('foo.localhost', $data);
|
||||||
|
|
||||||
$tenant_data = $tenant;
|
$tenant_data = $tenant;
|
||||||
unset($tenant_data['uuid']);
|
unset($tenant_data['id']);
|
||||||
unset($tenant_data['domain']);
|
unset($tenant_data['domain']);
|
||||||
|
|
||||||
$this->assertSame($data, $tenant_data);
|
$this->assertSame($data, $tenant_data);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Tests;
|
namespace Stancl\Tenancy\Tests;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\StorageDrivers\Database\TenantModel;
|
||||||
use Stancl\Tenancy\StorageDrivers\DatabaseStorageDriver;
|
use Stancl\Tenancy\StorageDrivers\DatabaseStorageDriver;
|
||||||
use Stancl\Tenancy\StorageDrivers\RedisStorageDriver;
|
use Stancl\Tenancy\StorageDrivers\RedisStorageDriver;
|
||||||
use Stancl\Tenancy\Tenant;
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
@ -17,7 +18,7 @@ class TenantStorageTest extends TestCase
|
||||||
|
|
||||||
$this->assertTrue(tenant()->all()->contains($abc));
|
$this->assertTrue(tenant()->all()->contains($abc));
|
||||||
|
|
||||||
tenant()->delete($abc['uuid']);
|
tenant()->delete($abc['id']);
|
||||||
|
|
||||||
$this->assertFalse(tenant()->all()->contains($abc));
|
$this->assertFalse(tenant()->all()->contains($abc));
|
||||||
}
|
}
|
||||||
|
|
@ -62,11 +63,11 @@ class TenantStorageTest extends TestCase
|
||||||
public function put_works_on_a_tenant_different_than_the_current_one_when_two_args_are_used()
|
public function put_works_on_a_tenant_different_than_the_current_one_when_two_args_are_used()
|
||||||
{
|
{
|
||||||
$tenant = tenant()->create('second.localhost');
|
$tenant = tenant()->create('second.localhost');
|
||||||
$uuid = $tenant['uuid'];
|
$id = $tenant['id'];
|
||||||
|
|
||||||
tenancy()->put('foo', 'bar', $uuid);
|
tenancy()->put('foo', 'bar', $id);
|
||||||
|
|
||||||
$this->assertSame('bar', tenancy()->get('foo', $uuid));
|
$this->assertSame('bar', tenancy()->get('foo', $id));
|
||||||
$this->assertNotSame('bar', tenant('foo'));
|
$this->assertNotSame('bar', tenant('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,15 +75,15 @@ class TenantStorageTest extends TestCase
|
||||||
public function put_works_on_a_tenant_different_than_the_current_one_when_a_single_arg_is_used()
|
public function put_works_on_a_tenant_different_than_the_current_one_when_a_single_arg_is_used()
|
||||||
{
|
{
|
||||||
$tenant = tenant()->create('second.localhost');
|
$tenant = tenant()->create('second.localhost');
|
||||||
$uuid = $tenant['uuid'];
|
$id = $tenant['id'];
|
||||||
|
|
||||||
$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, $id);
|
||||||
|
|
||||||
$this->assertSame($vals, tenancy()->get($keys, $uuid));
|
$this->assertSame($vals, tenancy()->get($keys, $id));
|
||||||
$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
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +153,7 @@ class TenantStorageTest extends TestCase
|
||||||
public function tenant_model_uses_correct_connection()
|
public function tenant_model_uses_correct_connection()
|
||||||
{
|
{
|
||||||
config(['tenancy.storage.db.connection' => 'foo']);
|
config(['tenancy.storage.db.connection' => 'foo']);
|
||||||
$this->assertSame('foo', (new Tenant)->getConnectionName());
|
$this->assertSame('foo', (new TenantModel)->getConnectionName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -196,6 +197,6 @@ class TenantStorageTest extends TestCase
|
||||||
tenancy()->put(['foo' => 'bar', 'abc' => 'xyz']);
|
tenancy()->put(['foo' => 'bar', 'abc' => 'xyz']);
|
||||||
$this->assertSame(['bar', 'xyz'], tenancy()->get(['foo', 'abc']));
|
$this->assertSame(['bar', 'xyz'], tenancy()->get(['foo', 'abc']));
|
||||||
|
|
||||||
$this->assertSame('bar', \DB::connection('central')->table('tenants')->where('uuid', tenant('uuid'))->first()->foo);
|
$this->assertSame('bar', \DB::connection('central')->table('tenants')->where('id', tenant('id'))->first()->foo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue