mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 15:54:03 +00:00
fix issue and add test
This commit is contained in:
parent
9520cbc811
commit
d024de8727
2 changed files with 22 additions and 3 deletions
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Listeners;
|
|||
|
||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||
use Stancl\Tenancy\Database\DatabaseManager;
|
||||
use Stancl\Tenancy\Events\Contracts\TenancyEvent;
|
||||
use Stancl\Tenancy\Events\Contracts\TenantEvent;
|
||||
|
||||
class CreateTenantConnection
|
||||
|
|
@ -15,10 +16,10 @@ class CreateTenantConnection
|
|||
) {
|
||||
}
|
||||
|
||||
public function handle(TenantEvent $event): void
|
||||
public function handle(TenancyEvent $event): void
|
||||
{
|
||||
/** @var TenantWithDatabase */
|
||||
$tenant = $event->tenant;
|
||||
/** @var TenantWithDatabase $tenant */
|
||||
$tenant = $event->tenancy->tenant;
|
||||
|
||||
$this->database->createTenantConnection($tenant);
|
||||
}
|
||||
|
|
|
|||
18
tests/ManualModeTest.php
Normal file
18
tests/ManualModeTest.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Listeners\CreateTenantConnection;
|
||||
use \Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
||||
test('manual tenancy initialization works', function () {
|
||||
Event::listen(TenancyInitialized::class, CreateTenantConnection::class);
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
expect(tenancy()->initialized)->toBeTrue();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue