From 5094940f23a07027e65950f8000717e3aa06f560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Mon, 30 Sep 2019 16:48:13 +0200 Subject: [PATCH] Add test for migrate-fresh --- src/Commands/MigrateFresh.php | 16 ++++++++-------- src/TenancyServiceProvider.php | 1 + tests/CommandsTest.php | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Commands/MigrateFresh.php b/src/Commands/MigrateFresh.php index 8fb54c52..a6fa70c5 100644 --- a/src/Commands/MigrateFresh.php +++ b/src/Commands/MigrateFresh.php @@ -12,13 +12,6 @@ final class MigrateFresh extends Command { use HasATenantsOption, DealsWithMigrations; - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'tenants:migrate-fresh'; - /** * The console command description. * @@ -26,6 +19,13 @@ final class MigrateFresh extends Command */ protected $description = 'Drop all tables and re-run all migrations for tenant(s)'; + public function __construct() + { + parent::__construct(); + + $this->setName('tenants:migrate-fresh'); + } + /** * Execute the console command. * @@ -42,7 +42,7 @@ final class MigrateFresh extends Command tenancy()->initialize($tenant); $this->call('db:wipe', [ - '--database' => $tenant->getDatabaseConnection(), + '--database' => $tenant->getConnectionName(), '--force' => true, ]); diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index c70c5418..0e847c4b 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -65,6 +65,7 @@ class TenancyServiceProvider extends ServiceProvider Commands\Migrate::class, Commands\Rollback::class, Commands\TenantList::class, + Commands\MigrateFresh::class, ]); $this->publishes([ diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index d7ffb3cd..22e29cf6 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -138,4 +138,22 @@ class CommandsTest extends TestCase $this->assertDirectoryExists(database_path('migrations/tenant')); $this->assertSame(file_get_contents(__DIR__ . '/Etc/modifiedHttpKernel.stub'), file_get_contents(app_path('Http/Kernel.php'))); } + + /** @test */ + public function migrate_fresh_command_works() + { + $this->assertFalse(Schema::hasTable('users')); + Artisan::call('tenants:migrate-fresh'); + $this->assertFalse(Schema::hasTable('users')); + tenancy()->init('test.localhost'); + $this->assertTrue(Schema::hasTable('users')); + + $this->assertFalse(DB::table('users')->exists()); + DB::table('users')->insert(['name' => 'xxx', 'password' => bcrypt('password'), 'email' => 'foo@bar.xxx']); + $this->assertTrue(DB::table('users')->exists()); + + // test that db is wiped + Artisan::call('tenants:migrate-fresh'); + $this->assertFalse(DB::table('users')->exists()); + } }