From dcf29ee8c91b81c2b1371bbc49d1be77732df8dc Mon Sep 17 00:00:00 2001 From: lukinovec Date: Wed, 31 Aug 2022 07:14:51 +0200 Subject: [PATCH] Add link command tests back --- src/Commands/Link.php | 2 -- tests/CommandsTest.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Commands/Link.php b/src/Commands/Link.php index 86207068..061f2d3d 100644 --- a/src/Commands/Link.php +++ b/src/Commands/Link.php @@ -50,8 +50,6 @@ class Link extends Command } } catch (Exception $exception) { $this->error($exception->getMessage()); - - return 1; } } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index e21f59e8..ffbc59ed 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -188,6 +188,43 @@ test('run command with array of tenants works', function () { ->expectsOutput('Tenant: ' . $tenantId2); }); +test('link command works', function() { + $tenantId1 = Tenant::create()->getTenantKey(); + $tenantId2 = Tenant::create()->getTenantKey(); + pest()->artisan('tenants:link'); + + $this->assertDirectoryExists(storage_path("tenant-$tenantId1/app/public")); + $this->assertEquals(storage_path("tenant-$tenantId1/app/public/"), readlink(public_path("public-$tenantId1"))); + + $this->assertDirectoryExists(storage_path("tenant-$tenantId2/app/public")); + $this->assertEquals(storage_path("tenant-$tenantId2/app/public/"), readlink(public_path("public-$tenantId2"))); + + pest()->artisan('tenants:link', [ + '--remove' => true, + ]); + + $this->assertDirectoryDoesNotExist(public_path("public-$tenantId1")); + $this->assertDirectoryDoesNotExist(public_path("public-$tenantId2")); +}); + +test('link command works with a specified tenant', function() { + $tenantKey = Tenant::create()->getTenantKey(); + + pest()->artisan('tenants:link', [ + '--tenants' => [$tenantKey], + ]); + + $this->assertDirectoryExists(storage_path("tenant-$tenantKey/app/public")); + $this->assertEquals(storage_path("tenant-$tenantKey/app/public/"), readlink(public_path("public-$tenantKey"))); + + pest()->artisan('tenants:link', [ + '--remove' => true, + '--tenants' => [$tenantKey], + ]); + + $this->assertDirectoryDoesNotExist(public_path("public-$tenantKey")); +}); + // todo@tests function runCommandWorks(): void {