From cf339a5e820df9fbba786282c055fe8131a125bc Mon Sep 17 00:00:00 2001 From: Devon Mather Date: Sat, 21 Mar 2020 02:05:17 +0100 Subject: [PATCH] Add return value to execute method (#333) * Add command for test * Write test to verify issue * Make test pass --- src/Traits/TenantAwareCommand.php | 2 ++ tests/Etc/AddUserCommand.php | 38 +++++++++++++++++++++++++ tests/Etc/ConsoleKernel.php | 1 + tests/Traits/TenantAwareCommandTest.php | 35 +++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 tests/Etc/AddUserCommand.php create mode 100644 tests/Traits/TenantAwareCommandTest.php diff --git a/src/Traits/TenantAwareCommand.php b/src/Traits/TenantAwareCommand.php index 6cdb22e8..2d18a265 100644 --- a/src/Traits/TenantAwareCommand.php +++ b/src/Traits/TenantAwareCommand.php @@ -26,6 +26,8 @@ trait TenantAwareCommand $this->laravel->call([$this, 'handle']); }); } + + return 1; } /** diff --git a/tests/Etc/AddUserCommand.php b/tests/Etc/AddUserCommand.php new file mode 100644 index 00000000..a270d158 --- /dev/null +++ b/tests/Etc/AddUserCommand.php @@ -0,0 +1,38 @@ + Str::random(10), + 'email' => Str::random(10) . '@gmail.com', + 'email_verified_at' => now(), + 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'remember_token' => Str::random(10), + ]); + } +} diff --git a/tests/Etc/ConsoleKernel.php b/tests/Etc/ConsoleKernel.php index a801b9dc..1bc66365 100644 --- a/tests/Etc/ConsoleKernel.php +++ b/tests/Etc/ConsoleKernel.php @@ -15,5 +15,6 @@ class ConsoleKernel extends Kernel */ protected $commands = [ ExampleCommand::class, + AddUserCommand::class, ]; } diff --git a/tests/Traits/TenantAwareCommandTest.php b/tests/Traits/TenantAwareCommandTest.php new file mode 100644 index 00000000..58cc33c8 --- /dev/null +++ b/tests/Traits/TenantAwareCommandTest.php @@ -0,0 +1,35 @@ +save(); + $tenant2 = Tenant::new()->save(); + \Artisan::call('tenants:migrate', [ + '--tenants' => [$tenant1['id'], $tenant2['id']], + ]); + + $this->artisan('user:add') + ->assertExitCode(1); + + tenancy()->initializeTenancy($tenant1); + $this->assertNotEmpty(\DB::table('users')->get()); + tenancy()->end(); + + tenancy()->initializeTenancy($tenant2); + $this->assertNotEmpty(\DB::table('users')->get()); + tenancy()->end(); + } +}