From c6a565295c9690ec2dd6c569f920bd4d5c1a79e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 30 Aug 2022 15:30:27 +0200 Subject: [PATCH] improve test --- tests/CommandsTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 7d44b3b3..cd2eed9d 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -16,6 +16,7 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Tests\Etc\ExampleSeeder; use Stancl\Tenancy\Tests\Etc\Tenant; +use Stancl\Tenancy\Tests\Etc\User; beforeEach(function () { Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { @@ -179,7 +180,7 @@ test('run command with array of tenants works', function () { ->expectsOutput('Tenant: ' . $tenantId2); }); -test('run command works when sub command asks question and accepts argument', closure: function () { +test('run command works when sub command asks question and accepts argument', function () { $tenant = Tenant::create(); $id = $tenant->getTenantKey(); @@ -191,13 +192,16 @@ test('run command works when sub command asks question and accepts argument', cl ->expectsOutput("Tenant: $id") ->expectsOutput("User created: Abrar(email@localhost)"); + // Assert we are in central context + expect(tenancy()->initialized)->toBeFalse(); + // Assert users table does not exist in the central context expect(Schema::hasTable('users'))->toBeFalse(); // Assert user created in tenant context tenancy()->initialize($tenant); expect(Schema::hasTable('users'))->toBeTrue(); - $user = \Stancl\Tenancy\Tests\Etc\User::first(); + $user = User::first(); // Assert user is same as provided using command expect($user->name)->toBe('Abrar');