mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:44:02 +00:00
Add tenancy()->end() (#68)
This commit is contained in:
parent
b2e2460c34
commit
353f7afb82
3 changed files with 132 additions and 7 deletions
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class TenantManagerTest extends TestCase
|
||||
{
|
||||
public $autoCreateTenant = false;
|
||||
|
|
@ -98,4 +101,80 @@ class TenantManagerTest extends TestCase
|
|||
$this->expectException(\Exception::class);
|
||||
tenancy()->findByDomain('nonexistent.domain');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function tenancy_can_be_ended()
|
||||
{
|
||||
$originals = [
|
||||
'databasePDO' => DB::connection()->getPDO(),
|
||||
'databaseName' => DB::connection()->getDatabaseName(),
|
||||
'storage_path' => storage_path(),
|
||||
'storage_root' => Storage::disk('local')->getAdapter()->getPathPrefix(),
|
||||
'cache' => app('cache'),
|
||||
];
|
||||
|
||||
// Verify that these assertions are the right way for testing this
|
||||
$this->assertSame($originals['databaseName'], DB::connection()->getDatabaseName());
|
||||
$this->assertSame($originals['storage_path'], storage_path());
|
||||
$this->assertSame($originals['storage_root'], Storage::disk('local')->getAdapter()->getPathPrefix());
|
||||
$this->assertSame($originals['cache'], app('cache'));
|
||||
|
||||
tenant()->create('foo.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
$this->assertNotSame($originals['databaseName'], DB::connection()->getDatabaseName());
|
||||
$this->assertNotSame($originals['storage_path'], storage_path());
|
||||
$this->assertNotSame($originals['storage_root'], Storage::disk('local')->getAdapter()->getPathPrefix());
|
||||
$this->assertNotSame($originals['cache'], app('cache'));
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
$this->assertSame($originals['databaseName'], DB::connection()->getDatabaseName());
|
||||
$this->assertSame($originals['storage_path'], storage_path());
|
||||
$this->assertSame($originals['storage_root'], Storage::disk('local')->getAdapter()->getPathPrefix());
|
||||
$this->assertSame($originals['cache'], app('cache'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function tenancy_can_be_ended_after_reidentification()
|
||||
{
|
||||
$originals = [
|
||||
'databasePDO' => DB::connection()->getPDO(),
|
||||
'databaseName' => DB::connection()->getDatabaseName(),
|
||||
'storage_path' => storage_path(),
|
||||
'storage_root' => Storage::disk('local')->getAdapter()->getPathPrefix(),
|
||||
'cache' => app('cache'),
|
||||
];
|
||||
|
||||
tenant()->create('foo.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
$this->assertNotSame($originals['databaseName'], DB::connection()->getDatabaseName());
|
||||
$this->assertNotSame($originals['storage_path'], storage_path());
|
||||
$this->assertNotSame($originals['storage_root'], Storage::disk('local')->getAdapter()->getPathPrefix());
|
||||
$this->assertNotSame($originals['cache'], app('cache'));
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
$this->assertSame($originals['databaseName'], DB::connection()->getDatabaseName());
|
||||
$this->assertSame($originals['storage_path'], storage_path());
|
||||
$this->assertSame($originals['storage_root'], Storage::disk('local')->getAdapter()->getPathPrefix());
|
||||
$this->assertSame($originals['cache'], app('cache'));
|
||||
|
||||
// Reidentify tenant
|
||||
tenant()->create('bar.localhost');
|
||||
tenancy()->init('bar.localhost');
|
||||
|
||||
$this->assertNotSame($originals['databaseName'], DB::connection()->getDatabaseName());
|
||||
$this->assertNotSame($originals['storage_path'], storage_path());
|
||||
$this->assertNotSame($originals['storage_root'], Storage::disk('local')->getAdapter()->getPathPrefix());
|
||||
$this->assertNotSame($originals['cache'], app('cache'));
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
$this->assertSame($originals['databaseName'], DB::connection()->getDatabaseName());
|
||||
$this->assertSame($originals['storage_path'], storage_path());
|
||||
$this->assertSame($originals['storage_root'], Storage::disk('local')->getAdapter()->getPathPrefix());
|
||||
$this->assertSame($originals['cache'], app('cache'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue