mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 05:04:03 +00:00
* fixed tests, remove method duplications, restore necessary inner classes * Update CommandsTest.php * temporary checks run on `shift-64622` on branch. * fixed `TestSeeder` class not resolved * fixed messed up names * removed `uses` from individual files and add it in `Pest` * extract tests to helpers * use pest dataset * Update AutomaticModeTest.php * newline * todo convention * resolve reviews * added `// todo@tests` * remove shift branch from CI workflow Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
9d08334f48
commit
3f347ecaf6
27 changed files with 500 additions and 368 deletions
|
|
@ -3,35 +3,24 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
||||
uses(Stancl\Tenancy\Tests\TestCase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
});
|
||||
|
||||
test('context is switched when tenancy is initialized', function () {
|
||||
config(['tenancy.bootstrappers' => [
|
||||
MyBootstrapper::class,
|
||||
]]);
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
expect(app('tenancy_initialized_for_tenant'))->toBe('acme');
|
||||
contextIsSwitchedWhenTenancyInitialized();
|
||||
});
|
||||
|
||||
test('context is reverted when tenancy is ended', function () {
|
||||
$this->context_is_switched_when_tenancy_is_initialized();
|
||||
contextIsSwitchedWhenTenancyInitialized();
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
|
|
@ -100,13 +89,31 @@ test('central helper doesnt change tenancy state when called in central context'
|
|||
expect(tenant())->toBeNull();
|
||||
});
|
||||
|
||||
// Helpers
|
||||
function bootstrap(\Stancl\Tenancy\Contracts\Tenant $tenant)
|
||||
// todo@tests
|
||||
function contextIsSwitchedWhenTenancyInitialized()
|
||||
{
|
||||
app()->instance('tenancy_initialized_for_tenant', $tenant->getTenantKey());
|
||||
config(['tenancy.bootstrappers' => [
|
||||
MyBootstrapper::class,
|
||||
]]);
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
expect(app('tenancy_initialized_for_tenant'))->toBe('acme');
|
||||
}
|
||||
|
||||
function revert()
|
||||
class MyBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
app()->instance('tenancy_ended', true);
|
||||
public function bootstrap(\Stancl\Tenancy\Contracts\Tenant $tenant)
|
||||
{
|
||||
app()->instance('tenancy_initialized_for_tenant', $tenant->getTenantKey());
|
||||
}
|
||||
|
||||
public function revert()
|
||||
{
|
||||
app()->instance('tenancy_ended', true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue