mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +00:00
Get rid of v3 test namespace
This commit is contained in:
parent
89936187ce
commit
6962ec29b9
20 changed files with 0 additions and 0 deletions
86
tests/AutomaticModeTest.php
Normal file
86
tests/AutomaticModeTest.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Tests\v3;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
use Stancl\Tenancy\Events\Listeners\BootstrapTenancy;
|
||||
use Stancl\Tenancy\Events\Listeners\RevertToCentralContext;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
|
||||
class AutomaticModeTest extends TestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function context_is_switched_when_tenancy_is_initialized()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
MyBootstrapper::class,
|
||||
]]);
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
$this->assertSame('acme', app('tenancy_initialized_for_tenant'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function context_is_reverted_when_tenancy_is_ended()
|
||||
{
|
||||
$this->context_is_switched_when_tenancy_is_initialized();
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
$this->assertSame(true, app('tenancy_ended'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function context_is_switched_when_tenancy_is_reinitialized()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
MyBootstrapper::class,
|
||||
]]);
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
$this->assertSame('acme', app('tenancy_initialized_for_tenant'));
|
||||
|
||||
$tenant2 = Tenant::create([
|
||||
'id' => 'foobar',
|
||||
]);
|
||||
|
||||
tenancy()->initialize($tenant2);
|
||||
|
||||
$this->assertSame('foobar', app('tenancy_initialized_for_tenant'));
|
||||
}
|
||||
}
|
||||
|
||||
class MyBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
public function start(\Stancl\Tenancy\Contracts\Tenant $tenant)
|
||||
{
|
||||
app()->instance('tenancy_initialized_for_tenant', $tenant->getTenantKey());
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
app()->instance('tenancy_ended', true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue