mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:14:04 +00:00
[4.x] Make TenantDump work when called outside the tenant context (#1015)
* Run TenantDump as passed tenant * Fix code style (php-cs-fixer) * Fix `tenants:dump` tests * Update dump command test * Remove redundant `tenant-schema.dump` unlinking * Delete duplicate test * Update test name Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
parent
9520cbc811
commit
cb7567a88a
2 changed files with 20 additions and 17 deletions
|
|
@ -25,7 +25,7 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
|||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
|
||||
beforeEach(function () {
|
||||
if (file_exists($schemaPath = database_path('schema/tenant-schema.dump'))) {
|
||||
if (file_exists($schemaPath = 'tests/Etc/tenant-schema-test.dump')) {
|
||||
unlink($schemaPath);
|
||||
}
|
||||
|
||||
|
|
@ -111,28 +111,30 @@ test('migrate command loads schema state', function () {
|
|||
|
||||
test('dump command works', function () {
|
||||
$tenant = Tenant::create();
|
||||
$schemaPath = 'tests/Etc/tenant-schema-test.dump';
|
||||
|
||||
Artisan::call('tenants:migrate');
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
expect($schemaPath)->not()->toBeFile();
|
||||
|
||||
Artisan::call('tenants:dump --path="tests/Etc/tenant-schema-test.dump"');
|
||||
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');
|
||||
Artisan::call('tenants:dump ' . "--tenant='$tenant->id' --path='$schemaPath'");
|
||||
|
||||
expect($schemaPath)->toBeFile();
|
||||
});
|
||||
|
||||
test('migrate command uses the correct schema path by default', function () {
|
||||
test('dump command generates dump at the passed path', function() {
|
||||
$tenant = Tenant::create();
|
||||
|
||||
Artisan::call('tenants:migrate');
|
||||
|
||||
expect($schemaPath = 'tests/Etc/tenant-schema-test.dump')->not()->toBeFile();
|
||||
|
||||
Artisan::call("tenants:dump --tenant='$tenant->id' --path='$schemaPath'");
|
||||
|
||||
expect($schemaPath)->toBeFile();
|
||||
});
|
||||
|
||||
test('migrate command correctly uses the schema dump located at the configured schema path by default', function () {
|
||||
config(['tenancy.migration_parameters.--schema-path' => 'tests/Etc/tenant-schema.dump']);
|
||||
$tenant = Tenant::create();
|
||||
|
||||
|
|
@ -146,6 +148,7 @@ test('migrate command uses the correct schema path by default', function () {
|
|||
|
||||
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
|
||||
expect(Schema::hasTable('schema_users'))->toBeTrue();
|
||||
expect(Schema::hasTable('users'))->toBeTrue();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue