1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:44:02 +00:00

[2.x] Allow automatic seeding after automatic migrations (#160)

This commit is contained in:
Chris Brown 2019-10-17 13:25:30 -04:00 committed by Samuel Štancl
parent 3dbbbe8b24
commit d5b01219fd
4 changed files with 113 additions and 6 deletions

View file

@ -12,8 +12,10 @@ use Stancl\Tenancy\Exceptions\TenantDoesNotExistException;
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseCreator;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseSeeder;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\TenantManager;
use Stancl\Tenancy\Tests\Etc\ExampleSeeder;
class TenantManagerTest extends TestCase
{
@ -237,6 +239,27 @@ class TenantManagerTest extends TestCase
$this->assertTrue(\Schema::hasTable('users'));
}
/** @test */
public function automatic_seeding_works()
{
config(['tenancy.migrate_after_creation' => true]);
$tenant = Tenant::create(['foo.localhost']);
tenancy()->initialize($tenant);
$this->assertSame(0, \DB::table('users')->count());
config([
'tenancy.seed_after_migration' => true,
'tenancy.seeder_parameters' => [
'--class' => ExampleSeeder::class,
],
]);
$tenant2 = Tenant::create(['bar.localhost']);
tenancy()->initialize($tenant2);
$this->assertSame(1, \DB::table('users')->count());
}
/** @test */
public function ensureTenantCanBeCreated_works()
{
@ -272,6 +295,25 @@ class TenantManagerTest extends TestCase
// $this->assertTrue(\Schema::hasTable('users'));
}
/** @test */
public function autoseeding_is_queued_when_db_creation_is_queued()
{
Queue::fake();
config([
'tenancy.queue_database_creation' => true,
'tenancy.migrate_after_creation' => true,
'tenancy.seed_after_migration' => true,
]);
Tenant::new()->save();
Queue::assertPushedWithChain(QueuedTenantDatabaseCreator::class, [
QueuedTenantDatabaseMigrator::class,
QueuedTenantDatabaseSeeder::class,
]);
}
/** @test */
public function TenantDoesNotExistException_is_thrown_when_find_is_called_on_an_id_that_does_not_belong_to_any_tenant()
{