Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asking for command and tenant #8

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Commands/TenantsArtisanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Multitenancy\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Artisan;
use Spatie\Multitenancy\Models\Tenant;

Expand All @@ -14,11 +15,17 @@ public function handle()
{
$tenantQuery = Tenant::query();

if ($tenantIds = $this->option('tenant')) {
$tenantQuery = $tenantQuery->whereIn('id', $tenantIds);
if (!$artisanCommand = $this->argument('artisanCommand')) {
$artisanCommand = $this->ask('Command to run?');
}

$artisanCommand = $this->argument('artisanCommand');
if (!$tenantIds = $this->option('tenant')) {
$tenantIds = $this->ask('What tenant ID? Nothing for all tenants.');
}

if ($tenantIds) {
$tenantQuery->whereIn('id', Arr::wrap($tenantIds));
}

$tenantQuery
->cursor()
Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/Commands/TenantsArtisanCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function setUp(): void
/** @test */
public function it_can_migrate_all_tenant_databases()
{
$this->artisan('tenants:artisan migrate')->assertExitCode(0);
$this->artisan('tenants:artisan migrate')
->expectsQuestion('What tenant ID? Nothing for all tenants.', '')
->assertExitCode(0);

$this
->assertTenantDatabaseHasTable($this->tenant, 'migrations')
Expand Down