From ea19117870a4f0bc091621d23aae70888cb5a799 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Wed, 23 Nov 2022 13:12:29 +0100 Subject: [PATCH] Use the hardcoded default path in `TenantDump` only if the path isn't configured (#1019) * Use the hardcoded tenant dump path only if the path isn't configured * Test generating tenant dump at the configured path --- src/Commands/TenantDump.php | 2 +- tests/CommandsTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Commands/TenantDump.php b/src/Commands/TenantDump.php index b02af71f..c7bd9b99 100644 --- a/src/Commands/TenantDump.php +++ b/src/Commands/TenantDump.php @@ -23,7 +23,7 @@ class TenantDump extends DumpCommand public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int { if (is_null($this->option('path'))) { - $this->input->setOption('path', database_path('schema/tenant-schema.dump')); + $this->input->setOption('path', config('tenancy.migration_parameters.--schema-path') ?? database_path('schema/tenant-schema.dump')); } $tenant = $this->option('tenant') diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 355fb429..d8484253 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -134,6 +134,20 @@ test('dump command generates dump at the passed path', function() { expect($schemaPath)->toBeFile(); }); +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('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();