From d864aa72c94233e1795aabe81651b44b40c4c918 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 20 Oct 2022 12:43:16 +0200 Subject: [PATCH] Move pending tenant tests to a more appropriate file --- tests/CommandsTest.php | 61 ------------------------------------ tests/PendingTenantsTest.php | 61 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 2e982db5..96395ec1 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -239,67 +239,6 @@ test('link command works with a specified tenant', function() { $this->assertDirectoryDoesNotExist(public_path("public-$tenantKey")); }); -test('commands do not run for pending tenants if tenancy.pending.include_in_queries is false and the with pending option does not get passed', function() { - config(['tenancy.pending.include_in_queries' => false]); - - $tenants = collect([ - Tenant::create(), - Tenant::create(), - Tenant::createPending(), - Tenant::createPending(), - ]); - - pest()->artisan('tenants:migrate --with-pending'); - - $artisan = pest()->artisan("tenants:run 'foo foo --b=bar --c=xyz'"); - - $pendingTenants = $tenants->filter->pending(); - $readyTenants = $tenants->reject->pending(); - - $pendingTenants->each(fn($tenant) => $artisan->doesntExpectOutputToContain("Tenant: {$tenant->getTenantKey()}")); - $readyTenants->each(fn($tenant) => $artisan->expectsOutputToContain("Tenant: {$tenant->getTenantKey()}")); - - $artisan->assertExitCode(0); -}); - -test('commands run for pending tenants too if tenancy.pending.include_in_queries is true', function() { - config(['tenancy.pending.include_in_queries' => true]); - - $tenants = collect([ - Tenant::create(), - Tenant::create(), - Tenant::createPending(), - Tenant::createPending(), - ]); - - pest()->artisan('tenants:migrate --with-pending'); - - $artisan = pest()->artisan("tenants:run 'foo foo --b=bar --c=xyz'"); - - $tenants->each(fn($tenant) => $artisan->expectsOutputToContain("Tenant: {$tenant->getTenantKey()}")); - - $artisan->assertExitCode(0); -}); - -test('commands run for pending tenants too if the with pending option is passed', function() { - config(['tenancy.pending.include_in_queries' => false]); - - $tenants = collect([ - Tenant::create(), - Tenant::create(), - Tenant::createPending(), - Tenant::createPending(), - ]); - - pest()->artisan('tenants:migrate --with-pending'); - - $artisan = pest()->artisan("tenants:run 'foo foo --b=bar --c=xyz' --with-pending"); - - $tenants->each(fn($tenant) => $artisan->expectsOutputToContain("Tenant: {$tenant->getTenantKey()}")); - - $artisan->assertExitCode(0); -}); - test('run command works when sub command asks questions and accepts arguments', function () { $tenant = Tenant::create(); $id = $tenant->getTenantKey(); diff --git a/tests/PendingTenantsTest.php b/tests/PendingTenantsTest.php index d6e17723..7811f253 100644 --- a/tests/PendingTenantsTest.php +++ b/tests/PendingTenantsTest.php @@ -141,3 +141,64 @@ test('pending events are dispatched', function () { Event::assertDispatched(PullingPendingTenant::class); Event::assertDispatched(PendingTenantPulled::class); }); + +test('commands do not run for pending tenants if tenancy.pending.include_in_queries is false and the with pending option does not get passed', function() { + config(['tenancy.pending.include_in_queries' => false]); + + $tenants = collect([ + Tenant::create(), + Tenant::create(), + Tenant::createPending(), + Tenant::createPending(), + ]); + + pest()->artisan('tenants:migrate --with-pending'); + + $artisan = pest()->artisan("tenants:run 'foo foo --b=bar --c=xyz'"); + + $pendingTenants = $tenants->filter->pending(); + $readyTenants = $tenants->reject->pending(); + + $pendingTenants->each(fn($tenant) => $artisan->doesntExpectOutputToContain("Tenant: {$tenant->getTenantKey()}")); + $readyTenants->each(fn($tenant) => $artisan->expectsOutputToContain("Tenant: {$tenant->getTenantKey()}")); + + $artisan->assertExitCode(0); +}); + +test('commands run for pending tenants too if tenancy.pending.include_in_queries is true', function() { + config(['tenancy.pending.include_in_queries' => true]); + + $tenants = collect([ + Tenant::create(), + Tenant::create(), + Tenant::createPending(), + Tenant::createPending(), + ]); + + pest()->artisan('tenants:migrate --with-pending'); + + $artisan = pest()->artisan("tenants:run 'foo foo --b=bar --c=xyz'"); + + $tenants->each(fn($tenant) => $artisan->expectsOutputToContain("Tenant: {$tenant->getTenantKey()}")); + + $artisan->assertExitCode(0); +}); + +test('commands run for pending tenants too if the with pending option is passed', function() { + config(['tenancy.pending.include_in_queries' => false]); + + $tenants = collect([ + Tenant::create(), + Tenant::create(), + Tenant::createPending(), + Tenant::createPending(), + ]); + + pest()->artisan('tenants:migrate --with-pending'); + + $artisan = pest()->artisan("tenants:run 'foo foo --b=bar --c=xyz' --with-pending"); + + $tenants->each(fn($tenant) => $artisan->expectsOutputToContain("Tenant: {$tenant->getTenantKey()}")); + + $artisan->assertExitCode(0); +});