mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 22:04:04 +00:00
Add and test Tenant::currentOrFail()
This commit is contained in:
parent
0198a30413
commit
54a4258fa4
2 changed files with 20 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ use Stancl\Tenancy\Jobs\CreateDatabase;
|
|||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Stancl\Tenancy\UUIDGenerator;
|
||||
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
|
||||
|
||||
test('created event is dispatched', function () {
|
||||
Event::fake([TenantCreated::class]);
|
||||
|
|
@ -153,6 +154,19 @@ test('the current method returns null if there is no currently initialized tenan
|
|||
expect(Tenant::current())->toBeNull();
|
||||
});
|
||||
|
||||
test('currentOrFail method returns the currently initialized tenant', function() {
|
||||
tenancy()->initialize($tenant = Tenant::create());
|
||||
|
||||
expect(Tenant::currentOrFail())->toBe($tenant);
|
||||
});
|
||||
|
||||
test('currentOrFail method throws an exception if there is no currently initialized tenant', function() {
|
||||
tenancy()->end();
|
||||
|
||||
expect(fn() => Tenant::currentOrFail())->toThrow(TenancyNotInitializedException::class);
|
||||
});
|
||||
|
||||
|
||||
class MyTenant extends Tenant
|
||||
{
|
||||
protected $table = 'tenants';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue