mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:54:04 +00:00
[1.7.0] Add Events system (#93)
* Add TenantManagerEvents * Apply fixes from StyleCI * Fix typos, add tests * end() events
This commit is contained in:
parent
d7358c588c
commit
c1df467601
3 changed files with 149 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Tenancy;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Stancl\Tenancy\Exceptions\CannotChangeUuidOrDomainException;
|
||||
|
|
@ -241,4 +242,72 @@ class TenantManagerTest extends TestCase
|
|||
$this->expectException(CannotChangeUuidOrDomainException::class);
|
||||
tenant()->put(['uuid' => 'foo']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function bootstrapping_event_works()
|
||||
{
|
||||
$uuid = tenant()->create('foo.localhost')['uuid'];
|
||||
|
||||
Tenancy::bootstrapping(function ($tenantManager) use ($uuid) {
|
||||
if ($tenantManager->tenant['uuid'] === $uuid) {
|
||||
config(['tenancy.foo' => 'bar']);
|
||||
}
|
||||
});
|
||||
|
||||
$this->assertSame(null, config('tenancy.foo'));
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', config('tenancy.foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function bootstrapped_event_works()
|
||||
{
|
||||
$uuid = tenant()->create('foo.localhost')['uuid'];
|
||||
|
||||
Tenancy::bootstrapped(function ($tenantManager) use ($uuid) {
|
||||
if ($tenantManager->tenant['uuid'] === $uuid) {
|
||||
config(['tenancy.foo' => 'bar']);
|
||||
}
|
||||
});
|
||||
|
||||
$this->assertSame(null, config('tenancy.foo'));
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', config('tenancy.foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function ending_event_works()
|
||||
{
|
||||
$uuid = tenant()->create('foo.localhost')['uuid'];
|
||||
|
||||
Tenancy::ending(function ($tenantManager) use ($uuid) {
|
||||
if ($tenantManager->tenant['uuid'] === $uuid) {
|
||||
config(['tenancy.foo' => 'bar']);
|
||||
}
|
||||
});
|
||||
|
||||
$this->assertSame(null, config('tenancy.foo'));
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame(null, config('tenancy.foo'));
|
||||
tenancy()->end();
|
||||
$this->assertSame('bar', config('tenancy.foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function ended_event_works()
|
||||
{
|
||||
$uuid = tenant()->create('foo.localhost')['uuid'];
|
||||
|
||||
Tenancy::ended(function ($tenantManager) use ($uuid) {
|
||||
if ($tenantManager->tenant['uuid'] === $uuid) {
|
||||
config(['tenancy.foo' => 'bar']);
|
||||
}
|
||||
});
|
||||
|
||||
$this->assertSame(null, config('tenancy.foo'));
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame(null, config('tenancy.foo'));
|
||||
tenancy()->end();
|
||||
$this->assertSame('bar', config('tenancy.foo'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue