From 33fcb8a936dad03fb7ed898db5fe22abd2a6c014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 9 Feb 2019 00:40:52 +0100 Subject: [PATCH] Cleanup commands --- src/Commands/Migrate.php | 16 ++++------------ src/Commands/Rollback.php | 16 ++++------------ src/Commands/Seed.php | 17 ++++------------- src/Traits/DealsWithMigrations.php | 11 +++++++++++ src/Traits/HasATenantsOption.php | 13 +++++++++++++ tests/CommandsTest.php | 24 ++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 37 deletions(-) create mode 100644 src/Traits/DealsWithMigrations.php create mode 100644 src/Traits/HasATenantsOption.php create mode 100644 tests/CommandsTest.php diff --git a/src/Commands/Migrate.php b/src/Commands/Migrate.php index e1e44c91..206aed32 100644 --- a/src/Commands/Migrate.php +++ b/src/Commands/Migrate.php @@ -5,11 +5,15 @@ namespace Stancl\Tenancy\Commands; use Illuminate\Console\Command; use Stancl\Tenancy\DatabaseManager; use Illuminate\Database\Migrations\Migrator; +use Stancl\Tenancy\Traits\HasATenantsOption; +use Stancl\Tenancy\Traits\DealsWithMigrations; use Symfony\Component\Console\Input\InputOption; use Illuminate\Database\Console\Migrations\MigrateCommand; class Migrate extends MigrateCommand { + use HasATenantsOption, DealsWithMigrations; + protected $database; /** @@ -54,16 +58,4 @@ class Migrate extends MigrateCommand parent::handle(); }); } - - protected function getOptions() - { - return array_merge([ - ['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null] - ], parent::getOptions()); - } - - protected function getMigrationPaths() - { - return [database_path('migrations/tenant')]; - } } diff --git a/src/Commands/Rollback.php b/src/Commands/Rollback.php index 919d66f8..24f9a592 100644 --- a/src/Commands/Rollback.php +++ b/src/Commands/Rollback.php @@ -5,11 +5,15 @@ namespace Stancl\Tenancy\Commands; use Illuminate\Console\Command; use Stancl\Tenancy\DatabaseManager; use Illuminate\Database\Migrations\Migrator; +use Stancl\Tenancy\Traits\HasATenantsOption; +use Stancl\Tenancy\Traits\DealsWithMigrations; use Symfony\Component\Console\Input\InputOption; use Illuminate\Database\Console\Migrations\RollbackCommand; class Rollback extends RollbackCommand { + use HasATenantsOption, DealsWithMigrations; + protected $database; /** @@ -54,16 +58,4 @@ class Rollback extends RollbackCommand parent::handle(); }); } - - protected function getOptions() - { - return array_merge([ - ['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null] - ], parent::getOptions()); - } - - protected function getMigrationPaths() - { - return [database_path('migrations/tenant')]; - } } diff --git a/src/Commands/Seed.php b/src/Commands/Seed.php index 04f94f48..7da3181c 100644 --- a/src/Commands/Seed.php +++ b/src/Commands/Seed.php @@ -4,6 +4,7 @@ namespace Stancl\Tenancy\Commands; use Illuminate\Console\Command; use Stancl\Tenancy\DatabaseManager; +use Stancl\Tenancy\Traits\HasATenantsOption; use Illuminate\Database\Migrations\Migrator; use Symfony\Component\Console\Input\InputOption; use Illuminate\Database\Console\Seeds\SeedCommand; @@ -11,6 +12,8 @@ use Illuminate\Database\ConnectionResolverInterface; class Seed extends SeedCommand { + use HasATenantsOption; + protected $database; /** @@ -51,20 +54,8 @@ class Seed extends SeedCommand $this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})"); $this->database->connectToTenant($tenant); - // Migrate + // Seed parent::handle(); }); } - - protected function getOptions() - { - return array_merge([ - ['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null] - ], parent::getOptions()); - } - - protected function getMigrationPaths() - { - return [database_path('migrations/tenant')]; - } } diff --git a/src/Traits/DealsWithMigrations.php b/src/Traits/DealsWithMigrations.php new file mode 100644 index 00000000..4c22dd10 --- /dev/null +++ b/src/Traits/DealsWithMigrations.php @@ -0,0 +1,11 @@ +markTestIncomplete(); + } + + /** @test */ + public function rollback_command_works() + { + $this->markTestIncomplete(); + } + + /** @test */ + public function seed_command_works() + { + $this->markTestIncomplete(); + } +}