mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 10:54:04 +00:00
Add test for migrate-fresh
This commit is contained in:
parent
e00793573f
commit
5094940f23
3 changed files with 27 additions and 8 deletions
|
|
@ -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,
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
Commands\Migrate::class,
|
||||
Commands\Rollback::class,
|
||||
Commands\TenantList::class,
|
||||
Commands\MigrateFresh::class,
|
||||
]);
|
||||
|
||||
$this->publishes([
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue