mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 16:34:04 +00:00
Fix tenants:dump tests
This commit is contained in:
parent
5499d1d0a6
commit
435284efc0
1 changed files with 34 additions and 16 deletions
|
|
@ -25,7 +25,7 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
if (file_exists($schemaPath = database_path('schema/tenant-schema.dump'))) {
|
if (file_exists($schemaPath = 'tests/Etc/tenant-schema-test.dump')) {
|
||||||
unlink($schemaPath);
|
unlink($schemaPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,28 +111,45 @@ test('migrate command loads schema state', function () {
|
||||||
|
|
||||||
test('dump command works', function () {
|
test('dump command works', function () {
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
|
$schemaPath = 'tests/Etc/tenant-schema-test.dump';
|
||||||
|
|
||||||
Artisan::call('tenants:migrate');
|
Artisan::call('tenants:migrate');
|
||||||
|
|
||||||
tenancy()->initialize($tenant);
|
expect($schemaPath)->not()->toBeFile();
|
||||||
|
|
||||||
Artisan::call('tenants:dump --path="tests/Etc/tenant-schema-test.dump"');
|
Artisan::call('tenants:dump ' . "--tenant='$tenant->id' --path='$schemaPath'");
|
||||||
expect('tests/Etc/tenant-schema-test.dump')->toBeFile();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('tenant dump file gets created as tenant-schema.dump in the database schema folder by default', function() {
|
|
||||||
config(['tenancy.migration_parameters.--schema-path' => $schemaPath = database_path('schema/tenant-schema.dump')]);
|
|
||||||
|
|
||||||
$tenant = Tenant::create();
|
|
||||||
Artisan::call('tenants:migrate');
|
|
||||||
|
|
||||||
tenancy()->initialize($tenant);
|
|
||||||
|
|
||||||
Artisan::call('tenants:dump');
|
|
||||||
|
|
||||||
expect($schemaPath)->toBeFile();
|
expect($schemaPath)->toBeFile();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('migrate command uses the correct schema path by default', function () {
|
test('dump command generates dump at the path specified in the tenancy migration parameters config', function() {
|
||||||
|
config(['tenancy.migration_parameters.--schema-path' => $schemaPath = 'tests/Etc/tenant-schema-test.dump']);
|
||||||
|
|
||||||
|
$tenant = Tenant::create();
|
||||||
|
|
||||||
|
Artisan::call('tenants:migrate');
|
||||||
|
|
||||||
|
expect($schemaPath)->not()->toBeFile();
|
||||||
|
|
||||||
|
Artisan::call("tenants:dump --tenant='$tenant->id'");
|
||||||
|
|
||||||
|
expect($schemaPath)->toBeFile();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('tenant dump file gets created at the path specified in the tenancy migration parameters config', function() {
|
||||||
|
$tenant = Tenant::create();
|
||||||
|
$schemaPath = 'tests/Etc/tenant-schema-test.dump';
|
||||||
|
|
||||||
|
Artisan::call('tenants:migrate');
|
||||||
|
|
||||||
|
expect($schemaPath)->not()->toBeFile();
|
||||||
|
|
||||||
|
Artisan::call("tenants:dump --tenant='$tenant->id' --path='$schemaPath'");
|
||||||
|
|
||||||
|
expect($schemaPath)->toBeFile();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('migrate command correctly uses the dump located at the configured schema path by default', function () {
|
||||||
config(['tenancy.migration_parameters.--schema-path' => 'tests/Etc/tenant-schema.dump']);
|
config(['tenancy.migration_parameters.--schema-path' => 'tests/Etc/tenant-schema.dump']);
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
|
|
||||||
|
|
@ -146,6 +163,7 @@ test('migrate command uses the correct schema path by default', function () {
|
||||||
|
|
||||||
tenancy()->initialize($tenant);
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
|
// schema_users is a table included in the tests/Etc/tenant-schema dump
|
||||||
// Check for both tables to see if missing migrations also get executed
|
// Check for both tables to see if missing migrations also get executed
|
||||||
expect(Schema::hasTable('schema_users'))->toBeTrue();
|
expect(Schema::hasTable('schema_users'))->toBeTrue();
|
||||||
expect(Schema::hasTable('users'))->toBeTrue();
|
expect(Schema::hasTable('users'))->toBeTrue();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue