mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-14 01:24:05 +00:00
Fix some tests
This commit is contained in:
parent
93d2a281eb
commit
50a77ee826
10 changed files with 76 additions and 61 deletions
|
|
@ -9,6 +9,7 @@ use Illuminate\Support\Facades\DB;
|
|||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
||||
class DataSeparationTest extends TestCase
|
||||
{
|
||||
|
|
@ -18,8 +19,8 @@ class DataSeparationTest extends TestCase
|
|||
/** @test */
|
||||
public function databases_are_separated()
|
||||
{
|
||||
$tenant1 = tenancy()->create('tenant1.localhost');
|
||||
$tenant2 = tenancy()->create('tenant2.localhost');
|
||||
$tenant1 = Tenant::create('tenant1.localhost');
|
||||
$tenant2 = Tenant::create('tenant2.localhost');
|
||||
\Artisan::call('tenants:migrate', [
|
||||
'--tenants' => [$tenant1['id'], $tenant2['id']],
|
||||
]);
|
||||
|
|
@ -52,7 +53,7 @@ class DataSeparationTest extends TestCase
|
|||
$this->assertSame('foo', User::first()->name);
|
||||
$this->assertSame('foo@bar.com', User::first()->email);
|
||||
|
||||
$tenant3 = tenancy()->create('tenant3.localhost');
|
||||
$tenant3 = Tenant::create('tenant3.localhost');
|
||||
\Artisan::call('tenants:migrate', [
|
||||
'--tenants' => [$tenant1['id'], $tenant3['id']],
|
||||
]);
|
||||
|
|
@ -72,8 +73,8 @@ class DataSeparationTest extends TestCase
|
|||
$this->markTestSkipped('Redis tenancy disabled.');
|
||||
}
|
||||
|
||||
tenancy()->create('tenant1.localhost');
|
||||
tenancy()->create('tenant2.localhost');
|
||||
Tenant::create('tenant1.localhost');
|
||||
Tenant::create('tenant2.localhost');
|
||||
|
||||
tenancy()->init('tenant1.localhost');
|
||||
Redis::set('foo', 'bar');
|
||||
|
|
@ -90,7 +91,7 @@ class DataSeparationTest extends TestCase
|
|||
$this->assertSame('bar', Redis::get('foo'));
|
||||
$this->assertSame(null, Redis::get('abc'));
|
||||
|
||||
tenancy()->create('tenant3.localhost');
|
||||
Tenant::create('tenant3.localhost');
|
||||
tenancy()->init('tenant3.localhost');
|
||||
$this->assertSame(null, Redis::get('foo'));
|
||||
$this->assertSame(null, Redis::get('abc'));
|
||||
|
|
@ -99,8 +100,8 @@ class DataSeparationTest extends TestCase
|
|||
/** @test */
|
||||
public function cache_is_separated()
|
||||
{
|
||||
tenancy()->create('tenant1.localhost');
|
||||
tenancy()->create('tenant2.localhost');
|
||||
Tenant::create('tenant1.localhost');
|
||||
Tenant::create('tenant2.localhost');
|
||||
|
||||
tenancy()->init('tenant1.localhost');
|
||||
Cache::put('foo', 'bar', 60);
|
||||
|
|
@ -117,7 +118,7 @@ class DataSeparationTest extends TestCase
|
|||
$this->assertSame('bar', Cache::get('foo'));
|
||||
$this->assertSame(null, Cache::get('abc'));
|
||||
|
||||
tenancy()->create('tenant3.localhost');
|
||||
Tenant::create('tenant3.localhost');
|
||||
tenancy()->init('tenant3.localhost');
|
||||
$this->assertSame(null, Cache::get('foo'));
|
||||
$this->assertSame(null, Cache::get('abc'));
|
||||
|
|
@ -126,8 +127,8 @@ class DataSeparationTest extends TestCase
|
|||
/** @test */
|
||||
public function filesystem_is_separated()
|
||||
{
|
||||
tenancy()->create('tenant1.localhost');
|
||||
tenancy()->create('tenant2.localhost');
|
||||
Tenant::create('tenant1.localhost');
|
||||
Tenant::create('tenant2.localhost');
|
||||
|
||||
tenancy()->init('tenant1.localhost');
|
||||
Storage::disk('public')->put('foo', 'bar');
|
||||
|
|
@ -144,7 +145,7 @@ class DataSeparationTest extends TestCase
|
|||
$this->assertSame('bar', Storage::disk('public')->get('foo'));
|
||||
$this->assertFalse(Storage::disk('public')->exists('abc'));
|
||||
|
||||
tenancy()->create('tenant3.localhost');
|
||||
Tenant::create('tenant3.localhost');
|
||||
tenancy()->init('tenant3.localhost');
|
||||
$this->assertFalse(Storage::disk('public')->exists('foo'));
|
||||
$this->assertFalse(Storage::disk('public')->exists('abc'));
|
||||
|
|
|
|||
|
|
@ -4,25 +4,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Tenancy;
|
||||
use Tenant;
|
||||
|
||||
class FacadeTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function tenant_manager_can_be_accessed_using_the_Tenancy_facade()
|
||||
{
|
||||
tenancy()->put('foo', 'bar');
|
||||
Tenancy::put('abc', 'xyz');
|
||||
|
||||
$this->assertSame('bar', Tenancy::get('foo'));
|
||||
$this->assertSame('xyz', Tenancy::get('abc'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function tenant_manager_can_be_accessed_using_the_Tenant_facade()
|
||||
{
|
||||
tenancy()->put('foo', 'bar');
|
||||
tenant()->put('foo', 'bar');
|
||||
Tenant::put('abc', 'xyz');
|
||||
|
||||
$this->assertSame('bar', Tenant::get('foo'));
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class TenantStorageTest extends TestCase
|
|||
/** @test */
|
||||
public function put_works_with_key_and_value_as_separate_args()
|
||||
{
|
||||
tenancy()->put('foo', 'bar');
|
||||
tenant()->put('foo', 'bar');
|
||||
|
||||
$this->assertSame('bar', tenant()->get('foo'));
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ class TenantStorageTest extends TestCase
|
|||
$vals = ['bar', 'xyz'];
|
||||
$data = \array_combine($keys, $vals);
|
||||
|
||||
tenancy()->put($data);
|
||||
tenant()->put($data);
|
||||
|
||||
$this->assertSame($vals, tenant()->get($keys));
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ class TenantStorageTest extends TestCase
|
|||
/** @test */
|
||||
public function put_on_the_current_tenant_pushes_the_value_into_the_tenant_property_array()
|
||||
{
|
||||
tenancy()->put('foo', 'bar');
|
||||
tenant()->put('foo', 'bar');
|
||||
|
||||
$this->assertSame('bar', tenancy()->tenant['foo']);
|
||||
}
|
||||
|
|
@ -65,9 +65,9 @@ class TenantStorageTest extends TestCase
|
|||
$tenant = Tenant::new()->withDomains(['second.localhost'])->save();
|
||||
$id = $tenant['id'];
|
||||
|
||||
tenancy()->put('foo', 'bar', $id);
|
||||
tenant()->put('foo', 'bar', $id);
|
||||
|
||||
$this->assertSame('bar', tenancy()->get('foo', $id));
|
||||
$this->assertSame('bar', tenant()->get('foo', $id));
|
||||
$this->assertNotSame('bar', tenant('foo'));
|
||||
}
|
||||
|
||||
|
|
@ -81,10 +81,10 @@ class TenantStorageTest extends TestCase
|
|||
$vals = ['bar', 'xyz'];
|
||||
$data = \array_combine($keys, $vals);
|
||||
|
||||
tenancy()->put($data, null, $id);
|
||||
tenant()->put($data, null, $id);
|
||||
|
||||
$this->assertSame($vals, tenancy()->get($keys, $id));
|
||||
$this->assertNotSame($vals, tenancy()->get($keys));
|
||||
$this->assertSame($vals, tenant()->get($keys, $id));
|
||||
$this->assertNotSame($vals, tenant()->get($keys));
|
||||
$this->assertFalse(\array_intersect($data, tenant()->tenant) == $data); // assert array not subset
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ class TenantStorageTest extends TestCase
|
|||
{
|
||||
$value = ['foo' => 'bar', 'abc' => 'xyz'];
|
||||
|
||||
$this->assertSame($value, tenancy()->put($value));
|
||||
$this->assertSame($value, tenant()->put($value));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
@ -132,21 +132,21 @@ class TenantStorageTest extends TestCase
|
|||
/** @test */
|
||||
public function data_is_stored_with_correct_data_types()
|
||||
{
|
||||
tenancy()->put('someBool', false);
|
||||
$this->assertSame('boolean', \gettype(tenancy()->get('someBool')));
|
||||
$this->assertSame('boolean', \gettype(tenancy()->get(['someBool'])[0]));
|
||||
tenant()->put('someBool', false);
|
||||
$this->assertSame('boolean', \gettype(tenant()->get('someBool')));
|
||||
$this->assertSame('boolean', \gettype(tenant()->get(['someBool'])[0]));
|
||||
|
||||
tenancy()->put('someInt', 5);
|
||||
$this->assertSame('integer', \gettype(tenancy()->get('someInt')));
|
||||
$this->assertSame('integer', \gettype(tenancy()->get(['someInt'])[0]));
|
||||
tenant()->put('someInt', 5);
|
||||
$this->assertSame('integer', \gettype(tenant()->get('someInt')));
|
||||
$this->assertSame('integer', \gettype(tenant()->get(['someInt'])[0]));
|
||||
|
||||
tenancy()->put('someDouble', 11.40);
|
||||
$this->assertSame('double', \gettype(tenancy()->get('someDouble')));
|
||||
$this->assertSame('double', \gettype(tenancy()->get(['someDouble'])[0]));
|
||||
tenant()->put('someDouble', 11.40);
|
||||
$this->assertSame('double', \gettype(tenant()->get('someDouble')));
|
||||
$this->assertSame('double', \gettype(tenant()->get(['someDouble'])[0]));
|
||||
|
||||
tenancy()->put('string', 'foo');
|
||||
$this->assertSame('string', \gettype(tenancy()->get('string')));
|
||||
$this->assertSame('string', \gettype(tenancy()->get(['string'])[0]));
|
||||
tenant()->put('string', 'foo');
|
||||
$this->assertSame('string', \gettype(tenant()->get('string')));
|
||||
$this->assertSame('string', \gettype(tenant()->get(['string'])[0]));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
@ -162,14 +162,14 @@ class TenantStorageTest extends TestCase
|
|||
Tenant::new()->withDomains(['foo.localhost'])->save();
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
tenancy()->put('foo', 'bar');
|
||||
$this->assertSame('bar', tenancy()->get('foo'));
|
||||
$this->assertSame(['bar'], tenancy()->get(['foo']));
|
||||
tenant()->put('foo', 'bar');
|
||||
$this->assertSame('bar', tenant()->get('foo'));
|
||||
$this->assertSame(['bar'], tenant()->get(['foo']));
|
||||
|
||||
tenancy()->endTenancy();
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', tenancy()->get('foo'));
|
||||
$this->assertSame(['bar'], tenancy()->get(['foo']));
|
||||
$this->assertSame('bar', tenant()->get('foo'));
|
||||
$this->assertSame(['bar'], tenant()->get(['foo']));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
@ -191,11 +191,11 @@ class TenantStorageTest extends TestCase
|
|||
'foo',
|
||||
]]);
|
||||
|
||||
tenancy()->create('foo.localhost');
|
||||
tenant()->create(['foo.localhost']);
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
tenancy()->put(['foo' => 'bar', 'abc' => 'xyz']);
|
||||
$this->assertSame(['bar', 'xyz'], tenancy()->get(['foo', 'abc']));
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,8 +126,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
protected function getPackageAliases($app)
|
||||
{
|
||||
return [
|
||||
'Tenancy' => \Stancl\Tenancy\Facades\Tenancy::class,
|
||||
'GlobalCache' => \Stancl\Tenancy\Facades\GlobalCache::class,
|
||||
'Tenant' => \Stancl\Tenancy\Facades\TenantFacade::class,
|
||||
'Tenancy' => \Stancl\Tenancy\Facades\TenancyFacade::class,
|
||||
'GlobalCache' => \Stancl\Tenancy\Facades\GlobalCacheFacade::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue