mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 15:34:04 +00:00
assert command executed in tenant context
This commit is contained in:
parent
851830420c
commit
e219bf8943
2 changed files with 36 additions and 8 deletions
|
|
@ -179,13 +179,29 @@ test('run command with array of tenants works', function () {
|
||||||
->expectsOutput('Tenant: ' . $tenantId2);
|
->expectsOutput('Tenant: ' . $tenantId2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('run command works when sub command asks question and accepts argument', function () {
|
test('run command works when sub command asks question and accepts argument', closure: function () {
|
||||||
$id = Tenant::create()->getTenantKey();
|
$tenant = Tenant::create();
|
||||||
|
$id = $tenant->getTenantKey();
|
||||||
|
|
||||||
pest()->artisan("tenants:run --tenants=$id 'age:ask Abrar' ")
|
// Run tenant migrations so we have users table
|
||||||
->expectsQuestion('What is your age?', 22)
|
Artisan::call('tenants:migrate');
|
||||||
|
|
||||||
|
pest()->artisan("tenants:run --tenants=$id 'user:addwithname Abrar' ")
|
||||||
|
->expectsQuestion('What is your email?', 'email@localhost')
|
||||||
->expectsOutput("Tenant: $id")
|
->expectsOutput("Tenant: $id")
|
||||||
->expectsOutput("Abrar's age is 22.");
|
->expectsOutput("User created: Abrar(email@localhost)");
|
||||||
|
|
||||||
|
// Assert users table does not exist in the central context
|
||||||
|
expect(Schema::hasTable('users'))->toBeFalse();
|
||||||
|
|
||||||
|
// Assert user created in tenant context
|
||||||
|
tenancy()->initialize($tenant);
|
||||||
|
expect(Schema::hasTable('users'))->toBeTrue();
|
||||||
|
$user = \Stancl\Tenancy\Tests\Etc\User::first();
|
||||||
|
|
||||||
|
// Assert user is same as provided using command
|
||||||
|
expect($user->name)->toBe('Abrar');
|
||||||
|
expect($user->email)->toBe('email@localhost');
|
||||||
});
|
});
|
||||||
|
|
||||||
// todo@tests
|
// todo@tests
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
namespace Stancl\Tenancy\Tests\Etc\Console;
|
namespace Stancl\Tenancy\Tests\Etc\Console;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Stancl\Tenancy\Tests\Etc\User;
|
||||||
|
|
||||||
class ExampleQuestionCommand extends Command
|
class ExampleQuestionCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
@ -11,7 +13,7 @@ class ExampleQuestionCommand extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'age:ask {name}';
|
protected $signature = 'user:addwithname {name}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
|
|
@ -27,8 +29,18 @@ class ExampleQuestionCommand extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$age = $this->ask('What is your age?');
|
$email = $this->ask('What is your email?');
|
||||||
|
|
||||||
$this->line($this->argument('name') . "'s age is $age.");
|
User::create([
|
||||||
|
'name' => $this->argument('name'),
|
||||||
|
'email' => $email,
|
||||||
|
'email_verified_at' => now(),
|
||||||
|
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
||||||
|
'remember_token' => Str::random(10),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->line("User created: ". $this->argument('name') . "($email)");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue