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

[2.x] Queued post-creation automigration (#154)

* Queued post-creation automigration

* Add shouldQueueMigration()

* Automigration test, config key, QueueTenancyBootstrapper support for QueueFake

* Apply fixes from StyleCI

* Fix if statement
This commit is contained in:
Samuel Štancl 2019-10-04 21:34:17 +02:00 committed by GitHub
parent b66574b1ab
commit abd0b8f04e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 6 deletions

View file

@ -5,9 +5,11 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\TenantManager;
@ -244,4 +246,24 @@ class TenantManagerTest extends TestCase
$this->expectException(TenantWithThisIdAlreadyExistsException::class);
Tenant::create(['bar.localhost'], ['id' => $id]);
}
/** @test */
public function automigration_can_be_queued()
{
Queue::fake();
config([
'tenancy.migrate_after_creation' => true,
'tenancy.queue_automatic_migration' => true,
]);
$tenant = Tenant::new()->save();
tenancy()->initialize($tenant);
Queue::assertPushed(QueuedTenantDatabaseMigrator::class);
$this->assertFalse(\Schema::hasTable('users'));
(new QueuedTenantDatabaseMigrator($tenant))->handle();
$this->assertTrue(\Schema::hasTable('users'));
}
}